admin管理员组文章数量:1418019
I'm learning node.js. I setup node and express on my machine. Then I used express auto project generator to setup a basic project. I could see my localhost:3000 page. But then something happened and it suddenly stopped working (obviously im not sure what happend).
I tried debugging and adding some console statements. It turns out ./bin/www file which is supposed to run on start up (specified in package.json) is not getting executed at all.
If I just add these 2 lines of code from ./bin/www to my app.js file everything seems to work fine.
var port = (process.env.PORT || '3000');
app.listen(port);
So I think culprit is bin/www file but I'm not sure why it is not getting executed at all?
In my package.json file I have this
"scripts": {
"start": "node ./bin/www"
},
Let me know if I should be posting any other information that can be helpful.
I'm learning node.js. I setup node and express on my machine. Then I used express auto project generator to setup a basic project. I could see my localhost:3000 page. But then something happened and it suddenly stopped working (obviously im not sure what happend).
I tried debugging and adding some console statements. It turns out ./bin/www file which is supposed to run on start up (specified in package.json) is not getting executed at all.
If I just add these 2 lines of code from ./bin/www to my app.js file everything seems to work fine.
var port = (process.env.PORT || '3000');
app.listen(port);
So I think culprit is bin/www file but I'm not sure why it is not getting executed at all?
In my package.json file I have this
"scripts": {
"start": "node ./bin/www"
},
Let me know if I should be posting any other information that can be helpful.
Share Improve this question asked Feb 27, 2015 at 6:49 sublimesublime 4,18110 gold badges57 silver badges97 bronze badges 4- how are you running app? using npm start or node app.js – Safi Commented Feb 27, 2015 at 7:17
- by running mand node app.js – sublime Commented Feb 27, 2015 at 23:55
- what is the difference between those 2? I have never heard anything about npm start – sublime Commented Feb 28, 2015 at 0:02
- If there is .bin/www in your applicaion that means you are using Express 4.0 . In case of Express 3.0 we need to run mand 'node app.js' but in case of Express 4.0 we need to run mand 'npm start' to run nodeJS application. So , here seems you are using Express 4.0, so run your application through 'npm start' – Arvind Kushwaha Commented Sep 4, 2015 at 6:29
3 Answers
Reset to default 2After using npm start
if the terminal shows
>node ./bin/www than it means your server is already running.
It will work just fine. Just manually paste: http://localhost:3000/ on your browser. You will get the braintree drop-in UI as expected.
Modify the scripts to:
"scripts": {
"start": "node ./bin/www/app.js"
},
and then use the mand npm start
Hope that helps!
It seems that you have not started node server.
Try adding following in app.js
:
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function () {
console.log('server listening on port ' + server.address().port);
});
Now start your server using node app
本文标签: javascriptNodejs binwww script not running on startupStack Overflow
版权声明:本文标题:javascript - Nodejs .binwww script not running on startup - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745283426a2651560.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论