我一直在使用node.js项目几个星期,它一直很好用.通常我使用'npm start'来运行我的应用程序,并在浏览器上的localhost,端口3000上查看它.
今天,我在使用npm start时开始出现以下错误:
Server started on port 3000
Port 3000 is already in use
Run Code Online (Sandbox Code Playgroud)
我检查了资源监视器,我没有在端口3000上运行其他进程.为什么我会收到此错误消息?
在我的app.js中,我有以下代码来设置端口......这是不正确的?它之前工作正常,所以我不确定我做错了什么.
// Set Port
app.set('port', (process.env.PORT || 3000));
app.listen(app.get('port'), function() {
console.log('Server started on port '+app.get('port'));
});
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
编辑:我已经尝试运行netstat和TCPView来检查使用该端口的进程,但没有使用该端口.我也试过重启我的笔记本电脑,但我仍然得到同样的错误.
寻找特殊问题的帮助。每次我停止并重新启动服务器时,都会收到以下消息:
Jim@Jim-PC MINGW64 ~/nodeProjects/express-locallibrary-tutorial
$ npm start
> express-locallibrary-tutorial@0.0.0 start C:\Users\Jim\nodeProjects\express-locallibrary-tutorial
> node ./bin/www
Port 3300 is already in use
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! express-locallibrary-tutorial@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the express-locallibrary-tutorial@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! …Run Code Online (Sandbox Code Playgroud)