node.js - Node 。并且 npm start 不起作用

标签 node.js express npm

标题说明了大部分问题。当我尝试运行 node . 我得到:

    module.js:340
    throw err;
          ^
Error: Cannot find module 'static-favicon'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

实际上似乎没有模块文件夹。我只是在一个空目录中运行 express

npm 但是工作正常。如果重要的话,这是一个全新的快速安装。任何帮助都会很棒,谢谢!

完整的错误信息:

 new-host-2:~ Brennan$ cd Desktop/
new-host-2:Desktop Brennan$ mkdir test4
new-host-2:Desktop Brennan$ cd test4
new-host-2:test4 Brennan$ express -e

   create : .
   create : ./package.json
   create : ./app.js
   create : ./public
   create : ./public/javascripts
   create : ./public/images
   create : ./public/stylesheets
   create : ./public/stylesheets/style.css
   create : ./routes
   create : ./routes/index.js
   create : ./routes/users.js
   create : ./views
   create : ./views/index.ejs
   create : ./views/error.ejs
   create : ./bin
   create : ./bin/www

   install dependencies:
     $ cd . && npm install

   run the app:
     $ DEBUG=test4 ./bin/www

new-host-2:test4 Brennan$ node app.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'static-favicon'
    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/Brennan/Desktop/test4/app.js:3: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)
new-host-2:test4 Brennan$ npm start app.js
npm ERR! Error: ENOENT, open '/Users/Brennan/Desktop/test4/node_modules/app.js/package.json'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Darwin 12.4.0
npm ERR! command "node" "/usr/local/bin/npm" "start" "app.js"
npm ERR! cwd /Users/Brennan/Desktop/test4
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.7
npm ERR! path /Users/Brennan/Desktop/test4/node_modules/app.js/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/Brennan/Desktop/test4/npm-debug.log
npm ERR! not ok code 0
new-host-2:test4 Brennan$ forever app.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms

module.js:340
    throw err;
          ^
Error: Cannot find module 'static-favicon'
    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/Brennan/Desktop/test4/app.js:3: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)
error: Forever detected script exited with code: 8

最佳答案

使用express-generator生成 Node 应用程序后,需要为项目安装依赖。这是通过:

$ npm install

完成后,您可以使用 npm 启动应用程序:

$ npm start

默认情况下,快速生成的应用程序将此声明为 npmstart 命令(您可以在 package.json 文件中查看):

"start": "node ./bin/www"

所以要通过命令行执行相同的操作,您需要运行:

$ node ./bin/www

关于node.js - Node 。并且 npm start 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24334005/

相关文章:

node.js - 通过语音 channel 播放音频的问题;音频被截断并且每个文件逐渐延迟

javascript - 当 header 中有 cookie 时无法读取 cookie

amazon-web-services - AWS Elastic Beanstalk HTTPS 不工作

npm - gulp-clean-css 无法为字体和图像等资源设置正确的 url() 相对路径

javascript - npm run dev 不工作

python - 消息未定义且主题成为缓冲区(ZMQ)

javascript - 使用 node.js 调用 chargebee 之类的 api

javascript - 等待 Promise 返回的第一个 true 的干净方式

node.js - 如何按照存储库模式从 nodeJS 应用程序中的服务和存储库中抛出错误

node.js - 尽管我使用 Npm 步骤配置为使用自定义 .nrpmrc 文件,但 npm 安装在 Jenkins 管道中失败