npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

set-node-env

v1.0.0

Published

Set node env from .env and .env.mode

Downloads

56

Readme

set-node-env

Set node env from a .env and a .env.mode files.

Build Status

Installation

npm install --save-dev set-node-env
// or
yarn add --dev set-node-env

Usage Demo

1. Create corresponding files under your project root directory as below

.env file

APP_NAME=set-node-env-demo

.env.development file

PORT=7777

.env.test file

PORT=8888

.env.production file

PORT=9999

app.js

console.log(process.env.APP_NAME)
console.log(process.env.PORT)
2. Run set-node-env command

package.json

"scripts": {
    "test": "set-node-env --mode=production --debug=true node app.js"
}
$ npm test
$ set-node-env-demo
$ 9999

or

$ ./node_modules/.bin/set-node-env --mode=production --debug=true node app.js
$ set-node-env-demo
$ 9999

Both .env and .env.prodocution will take affect.

3. (Optional and Alternative) Run below code instead of step above under your project root directory
$ node -r ./node_modules/set-node-env/preload.js app.js --env-mode=production --env-debug=true // node -r preload the specified module at startup
$ set-node-env-demo
$ 9999

Command Line Interface

Make sure set-env-node or node -r ./node_modules/set-node-env/preload.js command be executed under your project root directory since .env and .env.mode files were created there, that means set-node-env module code loads .env and .env.mode files under you current working directory.

  1. A .env file will always be tried to load even if it does not exist. A .env.mode file has a higher priority.
  2. If process.env has the key defined in .env or .env.mode files, new value will be ignored.
  3. If mode exists and process.env.NODE_ENV is undefined, set process.env.NODE_ENV=mode.
set-node-env --mode=production --debug=true node app.js

Options
  --mode             (optional) specify mode and must create a corresponding .env.mode file first
  --debug            (optional) show debug info or not, no specified means false, --debug means true
node -r ./node_modules/set-node-env/preload.js app.js --env-mode=production --env-debug=true

Options
  --env-mode         same as --mode
  --env-debug        same as --debug

More Examples

package.json

"scripts": {
    "node": "set-node-env --mode=production --debug=true node app.js",
    "electron": "set-node-env --mode=production --debug=true electron .", // install electron first
    "npx": "set-node-env --mode=production --debug=true npx electron .", // npm >= 5.2
    "npm": "set-node-env --mode=production --debug=true npm env"
}

LICENSE

MIT