Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does cross-env command works in nodejs?

I have the following line in my package.json

"scripts": {
  "start": "cross-env NODE_ENV=development node index.js"
}

I can see that "yarn start" command is running fine, but when I run "cross-env NODE_ENV=development node index.js" command directly in the terminal, I am getting the following error:

zsh: command not found: cross-env

If cross-env is not registered in the terminal, how does "yarn start" command works?

like image 484
yellowspectre Avatar asked Apr 10 '26 01:04

yellowspectre


1 Answers

https://docs.npmjs.com/cli/v7/configuring-npm/folders#executables

When in local mode, executables are linked into ./node_modules/.bin so that they can be made available to scripts run through npm. (For example, so that a test runner will be in the path when you run npm test.)

It's simply a feature to make things easier. It also means if you're working a project with multiple people, you only have to npm install --save a module--you don't have to worry about everyone in your project manually installing it globally. If you wish to run it yourself on the command line, you can either:

  • Install the module globally
  • Manually type in the command line ./node_modules/.bin/cross-env
  • Install npx and use npx cross-env
like image 140
DemiPixel Avatar answered Apr 11 '26 15:04

DemiPixel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!