Skip to content

Commit 33fa951

Browse files
authored
Upgrading to Node 10 and using the dotenv plugin (#50)
* Upgrading to Node 10 and using the dotenv plugin * Update serverless.yml * Update package.json
1 parent e8637b7 commit 33fa951

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ We use Jest to run our tests. You can read more about setting up your tests [her
113113

114114
To add environment variables to your project
115115

116-
1. Rename `env.example` to `env.yml`.
117-
2. Add environment variables for the various stages to `env.yml`.
118-
3. Uncomment `environment: ${file(env.yml):${self:provider.stage}}` in the `serverless.yml`.
119-
4. Make sure to not commit your `env.yml`.
116+
1. Rename `env.example` to `.env`.
117+
2. Add environment variables for your local stage to `.env`.
118+
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.
119+
4. Make sure to not commit your `.env`.
120120

121121
#### Linting
122122

env.example

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# HOW TO USE:
22
#
3-
# 1 Add environment variables for the various stages here
4-
# 2 Rename this file to env.yml and uncomment it's usage
3+
# 1 Add environment variables for local development.
4+
# 2 Rename this file to .env and uncomment it's usage
55
# in the serverless.yml.
66
# 3 Make sure to not commit this file.
77

8-
dev:
9-
APP_NAME: serverless-nodejs-starter
10-
11-
prod:
12-
APP_NAME: serverless-nodejs
8+
SAMPLE_ENV_VAR=i-am-an-environment-variable

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"url": "https://github.com/AnomalyInnovations/serverless-nodejs-starter.git"
1414
},
1515
"devDependencies": {
16-
"serverless-bundle": "^1.2.2",
16+
"serverless-bundle": "^1.2.5",
17+
"serverless-dotenv-plugin": "^2.1.1",
1718
"serverless-offline": "^5.3.3"
1819
},
1920
"dependencies": {}

serverless.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ package:
88
plugins:
99
- serverless-bundle # Package our functions with Webpack
1010
- serverless-offline
11+
- serverless-dotenv-plugin # Load .env as environment variables
1112

1213
provider:
1314
name: aws
14-
runtime: nodejs8.10
15+
runtime: nodejs10.x
1516
stage: dev
1617
region: us-east-1
1718
# To load environment variables externally
18-
# rename env.example to env.yml and uncomment
19+
# rename env.example to .env and uncomment
1920
# the following line. Also, make sure to not
20-
# commit your env.yml.
21+
# commit your .env.
2122
#
22-
#environment: ${file(env.yml):${self:provider.stage}}
23+
#environment:
24+
# sampleEnvVar: ${env:SAMPLE_ENV_VAR}
2325

2426
functions:
2527
hello:

0 commit comments

Comments
 (0)