我是Node和npm的新手,目前处于学习阶段。我能够运行服务器和npm启动之前,但我在我的项目目录中上传了一些文件夹后,npm start无法正常运行并且出现了一些错误。我需要帮助来理解我需要在项目中修复什么。
> workspace@1.0.0 start /home/ubuntu/workspace/nodeproject
> node app.js
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8080
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at Server._listen2 (net.js:1250:14)
at listen (net.js:1286:10)
at Server.listen (net.js:1382:5)
at EventEmitter.listen (/home/ubuntu/workspace/nodeproject/node_modules/express/lib/application.js:617:24)
at Object.<anonymous> (/home/ubuntu/workspace/nodeproject/app.js:14:5)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
npm ERR! Linux 4.2.0-c9
npm ERR! argv "/home/ubuntu/.nvm/versions/node/v4.5.0/bin/node" "/home/ubuntu/.nvm/versions/node/v4.5.0/bin/npm" "start"
npm ERR! node v4.5.0
npm ERR! npm v2.15.9
npm ERR! code ELIFECYCLE
npm ERR! workspace@1.0.0 start: `node app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the workspace@1.0.0 start script 'node app.js'.
npm ERR! This is most likely a problem with the workspace package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node app.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs workspace
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls workspace
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/ubuntu/workspace/nodeproject/npm-debug.log
答案 0 :(得分:0)
这不是npm本身的问题。
您已使用端口8080
,请尝试将其更改为例如
server.listen(8081)
如果您使用的是osx,请尝试将启动脚本从package.json更改为
env PORT=8081 node app.js
因为你的代码依赖于它。
另一方面,您可以手动设置
var port = 8081
app.listen(port, function(err){ console.log('The server is running on port: '+ port); });
答案 1 :(得分:0)
您可以在运行命令期间传递端口,如下所示
export PORT=3000 && npm start
您可以使用3000
以外的其他端口以及或,您可能希望更改内部代码,如下所示
var express = require("express");
var app = express();
var port = process.env.PORT | 3000;
app.get('/', function(req, res){
res.send('Aloha world!');
});
app.get('/routing', function(req, res){
res.send('Aloha Routing!');
});
app.listen(port, function(err){
console.log('The server is running on port: '+ port);
});
我刚刚更新了代码中的var port = process.env.PORT | 3000;
现在您可以浏览http://localhost:3000或http://localhost:3000/routing
我希望这可以帮助你:)。