Set the environment variable in the script command:
...
"scripts": {
"start": "node app.js",
"test": "NODE_ENV=test mocha --reporter spec"
},
...
Then use process.env.NODE_ENV
in your app.
Note: This is for Mac & Linux only. For Windows refer to the comments.
More Related Contents:
- How to set env var for .npmrc use
- What’s the difference between tilde(~) and caret(^) in package.json?
- What’s the difference between dependencies, devDependencies and peerDependencies in npm package.json file?
- NPM run * doesn’t do anything
- npm install private github repositories by dependency in package.json
- Is there a way to get version from package.json in nodejs code?
- How to use private Github repo as npm dependency
- How to use environment variables in package.json
- How do I fix a vulnerable npm package in my package-lock.json that isn’t listed in the package.json?
- What’s the difference between dependencies, devDependencies, and peerDependencies in NPM package.json file?
- How to fix npm throwing error without sudo
- Is there a way to make npm install (the command) to work behind proxy?
- How to install npm peer dependencies automatically?
- How can I specify the required Node.js version in package.json?
- NPM behind NTLM proxy
- npm can’t find package.json
- Module not found: Error can’t resolve ‘child_process’, how to fix?
- Is there any way to configure multiple registries in a single npmrc file
- How can I publish an npm package with distribution files?
- `npm install` fails on node-gyp rebuild with `gyp: No Xcode or CLT version detected!`
- How to fix npm vulnerabilities manually?
- npm install -g less does not work: EACCES: permission denied
- How to resolve Node.js: “Error: ENOENT: no such file or directory”
- Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (88)
- Can’t install any packages in Node.js using “npm install”
- npm: Why is a version “0.1” invalid?
- How to organise file structure of backend and frontend in MERN
- npm doesn’t work, get always this error -> Error: Cannot find module ‘are-we-there-yet’
- Can’t install any package with node npm
- Getting 404 when attempting to publish new package to NPM