Coder Social home page Coder Social logo

werever1001 / node-env-run Goto Github PK

View Code? Open in Web Editor NEW

This project forked from philnash/node-env-run

0.0 0.0 0.0 454 KB

๐Ÿƒ Node script to load .env variables and execute the give Node file afterwards

Home Page: https://npm.im/node-env-run

License: MIT License

JavaScript 8.20% TypeScript 91.80%

node-env-run's Introduction

npm npm npm Build Status All Contributors

node-env-run logo

node-env-run

Command-line tool to read .env files and execute scripts/commands after loading those environment variables

  • Uses dotenv under the hood
  • Easy to configure
  • Flexible command to execute
  • Let's you override existing environment variables

node-env-run example screenshot. Code below in Documentation section

Installation

Install per project:

I recommend installing this module as a devDependency for the respective project.

Install via yarn:

yarn add node-env-run --dev

Install via npm:

npm install node-env-run --save-dev

Install globally:

You can alternatively install the module globally if you want to:

npm install node-env-run --global

Usage

Add a new scripts entry to your package.json. Example:

{
  "scripts": {
    "dev": "nodenv .",
    "test": "nodenv -E test/.env test/test.js"
  }
}

Or use it with npx:

npx node-env-run .

Documentation

This module uses under the hood the dotenv module to parse the .env file. For more information about how to structure your .env file, please refer to its documentation.

Usage examples:

Start up the main file in package.json with the enviornment variables from .env:

nodenv .
More examples:

Start Node.js REPL with set environment variables from .env.repl:

nodenv -E .env.repl

Run Python file with overridden environment variables:

nodenv app.py --exec python --force

Run server.js file using nodemon:

nodenv server.js --exec nodemon

Pass --inspect flag for debugging after --:

nodenv someScript -- --inspect

Arguments

You can pass node-env-run a variety of arguments. These are the currently supported arguments:

Flag Type Description
--encoding string Lets you specify the encoding of the .env file. Defaults to utf8 encoding.
--env or
-E
string Specifies the path to the .env file that should be read
--exec or
-e
string This lets you specify a command other than node to execute the script with. More in the next section.
--force or -f boolean Flag to temporarily override existing environment variables with the ones in the .env file
--help boolean Displays the usage/help instructions
--verbose boolean Flag to enable more verbose logging
--version boolean Displays the current version of the package

Using node-env-run with other executables

You can use node-env-run with other executables. This is particularly useful if you try to combine it with things like babel-node or ts-node:

nodenv index.ts --exec "ts-node"

However, you can also use it with completely unrelated executables such as python:

nodenv app.py --exec python

Contributors


Dominik Kundel

๐Ÿ’ป

License

MIT

node-env-run's People

Contributors

dkundel avatar snyk-bot avatar ethanresnick avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.