[英]npm start error while running application
我是 Node 和 npm 的新手,目前處於學習階段。 我之前能夠運行服務器和 npm start,但是在我在項目目錄中上傳了一些文件夾之后,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
這不是 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); });
您可以在運行命令期間傳遞端口如下
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;
var port = process.env.PORT | 3000;
在你的代碼中
現在您可以瀏覽http://localhost:3000或http://localhost:3000/routing
我希望這對你有幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.