Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

by-node-env

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

by-node-env

Run package.json scripts by NODE_ENV.

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

by-node-env

Run package.json scripts by NODE_ENV.

Travis (.com) npm npm NPM

Installation

Install with npm:

npm install by-node-env

Install with pnpm:

pnpm install by-node-env

Install with Yarn:

yarn add by-node-env

Features

  • If NODE_ENV is defined in .env file found in root directory of your project, defaults to it.
  • Else, defaults NODE_ENV to development.
  • Customize process.env for each NODE_ENV.
  • Clearer, concise scripts.
  • No more Bash-scripting in package.json.
  • Works on Linux, macOS and Windows.
  • Compatible with npm, pnpm and Yarn.
  • Simplify your workflow:
    1. npm install or pnpm install or yarn add.
    2. npm start or pnpm start or yarn start.

Example

{
  // Processes spawned by by-node-env inherit environment-specific
  // variables, if defined.
  "by-node-env": {
    "production": {
      "DOCKER_USER": "my",
      "DOCKER_REPO": "project"
    }
  },
  "scripts": {
    // If NODE_ENV is missing, defaults to "development".
    "build": "by-node-env",

    "build:development": "webpack -d --watch",
    "build:staging": "webpack -p",
    "build:production": "webpack -p",

    // Deployment won't work unless NODE_ENV=production is explicitly set.
    "deploy": "by-node-env",

    "predeploy:production": "docker build -t ${DOCKER_USER}/${DOCKER_PROJECT} .",
    "deploy:production": "docker push ${DOCKER_USER}/${DOCKER_PROJECT}",

    // "npm start" is _the_ command to start the server across all environments.
    "start": "by-node-env",

    "start:development": "npm run build:development",

    "prestart:production": "npm run build",
    "start:production": "start-cluster build/server/server.js",

    "prestart:staging": "npm run build",
    "start:staging": "start-cluster build/server/server.js",

    // Explicitly set NODE_ENV, which is helpful in CI.
    "test": "NODE_ENV=test by-node-env",

    "test:test": "mocha"
  }
}

Notes

  • by-node-env is essentially a clone of per-env with some notable fixes:

    • pnpm compatibility.
    • Windows compatibility.
    • Yarn compatibility.
  • .env file found in root directory of your project is parsed using dotenv.

  • Option to specify custom file path for .env file is not yet implemented. Please raise an issue if you need it, PR is also welcomed.

Contributing

Do you encounter bugs or having new ideas?

Issues, comments and PRs are always welcomed!

Keywords

FAQs

Package last updated on 19 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc