2016-10-12 73 views
1

我是Node新手,npm目前处于学习阶段。我能够运行服务器和npm开始之前,但我上传了一些文件夹在我的项目目录npm开始没有工作,并给出了几个错误。我需要帮助理解我需要在我的项目中修复哪些内容。运行申请时npm启动错误

> [email protected] 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! [email protected] start: `node app.js` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] 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

您已经在另一个应用程序使用端口'8080'。您可能想更改端口,然后运行 –

+0

@ArifKhan您知道如何更改我对节点的新端口,但似乎无法找到该端口。我应该在app.js文件或其他目录中进行更改吗? – bmalhi

+0

尝试运行'export PORT = 8081 && npm start',然后在'8080'的地方使用'8081',或者您可以使用另一个端口如'3000',如果仍然不能工作,则发布'app.js'代码在你的问题,以便我们可以帮助你在需要修改的地方 –

回答

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); }); 
+0

我不确定在我的app.js文件中需要修复的东西,我可以在我的代码中引用它,它会很好 – bmalhi

+0

var express = require(“express”); var app = express(); var port = process.env.PORT; ('/',function(req,res){res35} app.get('/ routing',function(req,res){ res.send('Aloha Routing!'); }); (端口,函数(错误){ console.log('服务器在端口上运行:'+端口); }); – bmalhi

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:3000http://localhost:3000/routing

我希望这可以帮助您:)

+0

仍然npm没有运行,但我得到这个错误 – bmalhi

+0

'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! path /home/ubuntu/workspace/package.json npm ERR!代码ENOENT npm ERR! errno -2 npm ERR! enoent ENOENT:没有这样的文件或目录,打开'/ home/ubuntu/workspace/package。json' npm ERR! enoent这很可能不是npm本身的问题 npm ERR!并且与npm无法找到文件有关。 npm ERR! enoent npm ERR!请包括以下任何支持请求的文件: npm ERR!/home/ubuntu/workspace/npm-debug.log' – bmalhi

+0

@havenchyk你能帮我解决上述错误吗? – bmalhi