0

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 

> nodejs@0.0.0 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?

JDoe
  • 1
  • 2

2 Answers2

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

Sushant Magoo
  • 354
  • 4
  • 14
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.

just coding
  • 173
  • 13