Skip to content

Commit

Permalink
Upgrading to Node 10 and using the dotenv plugin (#50)
Browse files Browse the repository at this point in the history
* Upgrading to Node 10 and using the dotenv plugin

* Update serverless.yml

* Update package.json
  • Loading branch information
jayair authored Oct 9, 2019
1 parent e8637b7 commit 33fa951
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ We use Jest to run our tests. You can read more about setting up your tests [her

To add environment variables to your project

1. Rename `env.example` to `env.yml`.
2. Add environment variables for the various stages to `env.yml`.
3. Uncomment `environment: ${file(env.yml):${self:provider.stage}}` in the `serverless.yml`.
4. Make sure to not commit your `env.yml`.
1. Rename `env.example` to `.env`.
2. Add environment variables for your local stage to `.env`.
3. Uncomment `environment:` block in the `serverless.yml` and reference the environment variable as `${env:MY_ENV_VAR}`. Where `MY_ENV_VAR` is added to your `.env` file.
4. Make sure to not commit your `.env`.

#### Linting

Expand Down
10 changes: 3 additions & 7 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# HOW TO USE:
#
# 1 Add environment variables for the various stages here
# 2 Rename this file to env.yml and uncomment it's usage
# 1 Add environment variables for local development.
# 2 Rename this file to .env and uncomment it's usage
# in the serverless.yml.
# 3 Make sure to not commit this file.

dev:
APP_NAME: serverless-nodejs-starter

prod:
APP_NAME: serverless-nodejs
SAMPLE_ENV_VAR=i-am-an-environment-variable
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"url": "https://github.com/AnomalyInnovations/serverless-nodejs-starter.git"
},
"devDependencies": {
"serverless-bundle": "^1.2.2",
"serverless-bundle": "^1.2.5",
"serverless-dotenv-plugin": "^2.1.1",
"serverless-offline": "^5.3.3"
},
"dependencies": {}
Expand Down
10 changes: 6 additions & 4 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ package:
plugins:
- serverless-bundle # Package our functions with Webpack
- serverless-offline
- serverless-dotenv-plugin # Load .env as environment variables

provider:
name: aws
runtime: nodejs8.10
runtime: nodejs10.x
stage: dev
region: us-east-1
# To load environment variables externally
# rename env.example to env.yml and uncomment
# rename env.example to .env and uncomment
# the following line. Also, make sure to not
# commit your env.yml.
# commit your .env.
#
#environment: ${file(env.yml):${self:provider.stage}}
#environment:
# sampleEnvVar: ${env:SAMPLE_ENV_VAR}

functions:
hello:
Expand Down

0 comments on commit 33fa951

Please sign in to comment.