Node.js Node js Express module.js:340

Node.js Node js Express module.js:340,node.js,express,Node.js,Express,在节点中运行我的应用程序时遇到问题。当我第一次得到module.js:340错误时,我使用了一个sudo npm install express-g,它看起来像是安装了express,但当我再次运行我的应用程序时,我得到了这个错误 module.js:340 throw err; ^ Error: Cannot find module 'express' at Function.Module._resolveFilenam

在节点中运行我的应用程序时遇到问题。当我第一次得到
module.js:340
错误时,我使用了一个
sudo npm install express-g
,它看起来像是安装了express,但当我再次运行我的应用程序时,我得到了这个错误

   module.js:340
        throw err;
              ^
    Error: Cannot find module 'express'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:280:25)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.<anonymous> (/Users/mac/Downloads/node-FED-master/app.js:6:15)
        at Module._compile (module.js:456:26)
        at Object.Module._extensions..js (module.js:474:10)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:312:12)
        at Function.Module.runMain (module.js:497:10)
    users-Mac-Pro:node-FED-master mac$ 
module.js:340
犯错误;
^
错误:找不到模块“express”
在Function.Module.\u解析文件名(Module.js:338:15)
在Function.Module.\u加载(Module.js:280:25)
at Module.require(Module.js:364:17)
根据需要(模块js:380:17)
反对。(/Users/mac/Downloads/node-FED-master/app.js:6:15)
在模块处编译(Module.js:456:26)
在Object.Module.\u extensions..js(Module.js:474:10)
在Module.load(Module.js:356:32)
在Function.Module.\u加载(Module.js:312:12)
位于Function.Module.runMain(Module.js:497:10)
用户Mac Pro:node-FED主Mac$

您已经全局安装了Express(使用
-g
),这使您可以访问
Express
命令行工具,但节点程序无法访问全局模块。您需要通过在项目目录中执行
npm install Express
在本地安装Express。

如果项目有
包.json
,则项目目录中的一个简单的
npm install
将在其正确版本中安装所有必要的依赖项