Npm bs npx
#3203
|
Why in nodejs when we need to run script we do nom run dev but when we need to run the testing (jest or supertest ) we do npx jest |
Answered by
M677871
Mar 24, 2026
Replies: 1 comment
|
node runs a file. npm run runs a named script from package.json. npx runs a package binary. So: npm run dev works because dev is usually a script alias, like "dev": "next dev" node jest usually does not work because jest is not a file path you are passing to Node. The closer equivalent would be something ugly like: node ./node_modules/jest/bin/jest.js In practice, for tests, npm test / npm run test is usually better than npx jest if Jest is already in your project. |
0 replies
Answer selected by
A062025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
node runs a file. npm run runs a named script from package.json. npx runs a package binary.
So:
npm run dev works because dev is usually a script alias, like "dev": "next dev"
npx jest works because jest is a CLI from node_modules/.bin
node jest usually does not work because jest is not a file path you are passing to Node. The closer equivalent would be something ugly like:
node ./node_modules/jest/bin/jest.js
In practice, for tests, npm test / npm run test is usually better than npx jest if Jest is already in your project.