1

I'm learning NodeJS, I made a script using express-generator. It works great when I run npm start app.js:

root@server:~ $ npm start app.js 

> [email protected] start /root/nodejs
> node ./bin/www "app.js"

However, if I try to use node or nodejs, it doesn't work at all:

root@server:~ $ node app.js 
root@server:~ $ node app
root@server:~ $ nodejs app.js 
root@server:~ $ nodejs app
root@server:~ $

Here are the versions I am using:

root@server:~ $ nodejs -v
v8.11.4
root@server:~ $ node -v
v8.11.4
root@server:~ $ npm -v
5.6.0

Why doesn't it work?

1
  • please check your start script in package.json file. Commented Aug 19, 2018 at 6:37

2 Answers 2

1

For express project created using express-generator, this command will work node ./bin/www instead of node app.js. In package.json you will see that "scripts": {"start": "node ./bin/www"}, which start your project with npm start. By default only node command works on terminal/CMD like node --version and nodejs do nothing. npm is node package manager and gets installed when you install nodejs on your system. npm --version will show the npm version

Sign up to request clarification or add additional context in comments.

Comments

0

please check your package.json. default command to start the project is "start"

"scripts": {
    "start": "node ./bin/www"

whereas the command used for node -v is for the node application and not related to the project, I mean related to the scripting of the project.

if possible check this npm start vs node app.js

you should go through https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs

its a dev guide from Mozilla. it will make you better understand the concepts related to express.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.