javascript - Nodejs .binwww script not running on startup - Stack Overflow

I'm learning node.js. I setup node and express on my machine. Then I used express auto project gen

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
Add a ment  | 

3 Answers 3

Reset to default 2

After 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745283426a4620415.html

相关推荐

  • javascript - Nodejs .binwww script not running on startup - Stack Overflow

    I'm learning node.js. I setup node and express on my machine. Then I used express auto project gen

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信