JDoe
JDoe

Reputation: 11

node and nodejs commands do nothing while npm works

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?

Upvotes: 1

Views: 1782

Answers (2)

just coding
just coding

Reputation: 193

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.

Upvotes: 0

Sushant Magoo
Sushant Magoo

Reputation: 374

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

Upvotes: 1

Related Questions