1 | # Neutrino Environment Middleware
|
2 |
|
3 | `@neutrinojs/env` is Neutrino middleware for injecting environment variable definitions into
|
4 | source code at `process.env`. You can use this to make a custom environment variable (e.g. an API server backend to
|
5 | use) available inside your project. Always injects `process.env.NODE_ENV`, unless overridden.
|
6 |
|
7 | [![NPM version][npm-image]][npm-url]
|
8 | [![NPM downloads][npm-downloads]][npm-url]
|
9 | [![Join the Neutrino community on Spectrum][spectrum-image]][spectrum-url]
|
10 |
|
11 | ## Requirements
|
12 |
|
13 | - Node.js v6.10+
|
14 | - Yarn or npm client
|
15 | - Neutrino v8
|
16 |
|
17 | ## Installation
|
18 |
|
19 | `@neutrinojs/env` can be installed via the Yarn or npm clients.
|
20 |
|
21 | #### Yarn
|
22 |
|
23 | ```bash
|
24 | ❯ yarn add @neutrinojs/env
|
25 | ```
|
26 |
|
27 | #### npm
|
28 |
|
29 | ```bash
|
30 | ❯ npm install --save @neutrinojs/env
|
31 | ```
|
32 |
|
33 | ## Usage
|
34 |
|
35 | `@neutrinojs/env` can be consumed from the Neutrino API, middleware, or presets. Require this package
|
36 | and plug it into Neutrino:
|
37 |
|
38 | ```js
|
39 | // Using function middleware format
|
40 | const env = require('@neutrinojs/env');
|
41 |
|
42 | // Use with default options
|
43 | neutrino.use(env);
|
44 |
|
45 | // Usage with additional environment variables
|
46 | neutrino.use(env, ['SECRET_KEY']);
|
47 | ```
|
48 |
|
49 | ```js
|
50 | // Using object or array middleware format
|
51 |
|
52 | // Use with default options
|
53 | module.exports = {
|
54 | use: ['@neutrinojs/env']
|
55 | };
|
56 |
|
57 | // Usage with additional environment variables
|
58 | module.exports = {
|
59 | use: [
|
60 | ['@neutrinojs/env', ['SECRET_KEY']]
|
61 | ]
|
62 | };
|
63 | ```
|
64 |
|
65 | This middleware optionally accepts an array of environment variables to additionally inject into source code.
|
66 |
|
67 | ## Customization
|
68 |
|
69 | `@neutrinojs/env` creates some conventions to make overriding the configuration easier once you are ready to
|
70 | make changes.
|
71 |
|
72 | ### Plugins
|
73 |
|
74 | The following is a list of plugins and their identifiers which can be overridden:
|
75 |
|
76 | | Name | Description | Environments and Commands |
|
77 | | --- | --- | --- |
|
78 | | `env` | Inject environment variables into source code at `process.env`. | all |
|
79 |
|
80 | ## Contributing
|
81 |
|
82 | This middleware is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo
|
83 | containing all resources for developing Neutrino and its core presets and middleware. Follow the
|
84 | [contributing guide](https://neutrino.js.org/contributing) for details.
|
85 |
|
86 | [npm-image]: https://img.shields.io/npm/v/@neutrinojs/env.svg
|
87 | [npm-downloads]: https://img.shields.io/npm/dt/@neutrinojs/env.svg
|
88 | [npm-url]: https://npmjs.org/package/@neutrinojs/env
|
89 | [spectrum-image]: https://withspectrum.github.io/badge/badge.svg
|
90 | [spectrum-url]: https://spectrum.chat/neutrino
|