The two of these commands aren't necessarily the same. npm start
runs whatever the 'start' script config says to run as defined in your 'package.json', node app.js
executes the 'app.js' file in 'node'. See http://browsenpm.org/package.json for more info. So if you had the following package.json then the commands are completely different.
{
"name": "my cool node project",
....
"scripts": {
"start": "node index.js"
}
....
}
The following package.json is what you'll want to make them identical.
{
"name": "my cool node project",
....
"scripts": {
"start": "node app.js"
}
....
}
I'd start by checking what the 'start' script is set to run and try running the same command directly in your CLI rather than through NPM to see where the difference is.
but why is it that one successfully listens and the other doesn't
If the server is returning a 404 this would suggest the server is listening, but either the document root or access permissions aren't being setup properly so it returns a 'File not Found' response.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…