https://github.com/signiant/serverless-node-config-plugin
Uses node-config to load a configuration file during serverless deployment
https://github.com/signiant/serverless-node-config-plugin
Last synced: about 1 year ago
JSON representation
Uses node-config to load a configuration file during serverless deployment
- Host: GitHub
- URL: https://github.com/signiant/serverless-node-config-plugin
- Owner: Signiant
- License: mit
- Created: 2016-10-17T14:57:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-17T15:36:35.000Z (over 9 years ago)
- Last Synced: 2025-01-16T02:24:24.497Z (over 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 2
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Serverless Node Config Plugin
[](http://www.serverless.com)
A Serverless v1.0 plugin to pre-compile a [node-config](https://github.com/lorenwest/node-config)
configuration and include it in a deployment package.
## Install
*Until published to NPM*
Install plugin
```
npm install --save-dev Signiant/serverless-node-config-plugin
```
Add the plugin to your `serverless.yml` file:
```yaml
plugins:
- serverless-node-config-plugin
```
## Configure
### Node Config Environment Variables
Node config determines which configuration files to read and merge
by looking at specific environment variables. [More info here](https://github.com/lorenwest/node-config/wiki/Configuration-Files)
This plugin uses node-config to load the configuration at serverless
deploy time. Therefore any relevant environment variables present will
determine which config files are loaded.
For example, the following will merge and generate a config file from source files
`default`, `development`, `development-a`
```
bash-3.2$ export NODE_ENV='development'
bash-3.2$ export NODE_APP_INSTANCE='a'
bash-3.2$ serverless deploy
```
You can also set the node-config specific environment variables in the
custom section of `serverless.yaml`
```yaml
custom:
nodeConfigNodeEnv: development
nodeConfigHostname: ${opt:stage, self:provider.stage}
nodeConfigAppInstance: a
```
### Temporary Working Directory
By default the plugin will create a temporary working directory called
`.node-config` with the working directory. It will copy the service
contents here before modifying them, and will delete the directory when
completed.
This can be over-ridden by setting the `nodeConfigTmpDir` custom variable.
```yaml
custom:
nodeConfigTmpDir: ./myTmpDir
```
## Usage
Your project must include the node-config project
```
npm install --save node-config
```
From here you can just use the node-config project as designed.
```
let config = require('config')
```
When deployed, the config module will be replaced with a pre-compiled
configuration based on the environment variables present at deploy-time.
## Known Issues
* This plugin does not work with other plugins that manipulate files
during the `createDeploymentArtifacts` phase of the serverless deploy.
For example [serverless-webpack](https://github.com/elastic-coders/serverless-webpack)
## Todo
* NPM publish
* Play nicely with other packaging plugins (e.g. serverless-webpack)