Error: Cannot find module 'connect'

后端 未结 8 1863
孤街浪徒
孤街浪徒 2021-02-19 21:27

It appears that this simple app can\'t find the \'connect\' module after I just installed it in the file directory.

var connect = require (\'connec         


        
8条回答
  •  死守一世寂寞
    2021-02-19 21:40

    Connect is an extensible HTTP server framework that Express uses. In particular Express uses it provide support for sessions and cookie handling. The source code is available on github at https://github.com/senchalabs/connect.

    Generally when a node application 'can't find' something the first thing to try is to go to https://npmjs.org/package/npm-search and search for what can't be found. It would be hard to get along in the node eco-system without using npm.

    In this case npmsearch will find connect and if you go to https://npmjs.org/package/connect you'll find the installation instructions for the connect module.

    In this case :

    npm install connect
    
    npm -g install connect 
    

    installs the connect module for every user.

    You may need to be root or use sudo to do this on most unix distributions.

    Alternatively you can add the connect dependency to your project's package.json file - mine looks like this:

    "express": "3.x" ,
    "connect": "2.x"
    

    I also had to use npm to install the modules buffer-crc32, methods, debug, fresh, range-parser, cookie-signature and cookie to get a working express project.

    Happy node hacking :)

提交回复
热议问题