我是节点js和编程的新手。我在运行服务器时遇到问题。这就是我所做的
1)安装Express
sudo npm install -g express-generator
2)安装依赖项
cd . && sudo npm install
当我在终端跑步时:
node app.js OR node app
对于服务器是否正在运行没有响应,并且当我路由到localhost:3000时,chrome表示没有收到任何数据。我后来发现正确的方法是运行
npm start
相反,但我得到了这个:
npm ERR! express@0.0.1 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the express@0.0.1 start script.
npm ERR! This is most likely a problem with the express package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls express
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 13.1.0
npm ERR! command "/opt/node/bin/node" "/opt/node/bin/npm" "start"
npm ERR! cwd /Users/apple/Documents/javascript/express
npm ERR! node -v v0.11.14-pre
npm ERR! npm -v 1.4.14
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/apple/Documents/javascript/express/npm-debug.log
npm ERR! not ok code 0
怎么了?
答案 0 :(得分:0)
当您运行node app.js
时,您获得了什么回报?
另外,请确保您的app.js
位于您所在的文件夹内。
答案 1 :(得分:0)
Express生成器不会为您生成快递,它只会安装express
工具来生成项目。
sudo npm install -g express-generator
安装express-generator
后;问题express
为您生成项目;
$ express myapp
// generate myapp with initial express files
$ cd myapp && npm install
// now you run the app
$ ./bin/www
// or
$ npm start