Difference between npm run start and node server.js

What is the difference between running the application using

1)

node server.js

and making a script

"start" : "node server.js"

using

npm run start.

When i type

1)

node server.js | pino-pretty

in terminal there is an error

pino-pretty not found

When i make

"start": "node server.js | pino-pretty"

in package.json and type

npm run start

in terminal it works.

So apparently there is a fundamental difference between running the application in 1 and 2.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The difference is PATH.

Per the npm run docs:

In addition to the shell’s pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts.

You’ll find pino-pretty in node_modules/.bin.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x