Skip to content

Commit

Permalink
Offline update (#26)
Browse files Browse the repository at this point in the history
* add env and offline support (#19)

* Adding more comments on env.yml

* Updating serverless-offline

* Formatting comments

* Update README.md
  • Loading branch information
jayair authored Mar 26, 2018
1 parent 5ae5218 commit 6ba62cd
Show file tree
Hide file tree
Showing 6 changed files with 632 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ Session.vim
# Serverless
.webpack
.serverless

#env
env.yml
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# Serverless Node.js Starter

A Serverless starter that adds ES7 async/await and unit test support. Part of the [Serverless Stack](http://serverless-stack.com) guide.
A Serverless starter that adds ES7 async/await, serverless-offline, environment variables, and unit test support. Part of the [Serverless Stack](http://serverless-stack.com) guide.

[Serverless Node.js Starter](https://github.com/AnomalyInnovations/serverless-nodejs-starter) uses the [serverless-webpack](https://github.com/serverless-heaven/serverless-webpack) plugin, [Babel](https://babeljs.io), and [Jest](https://facebook.github.io/jest/). It supports:

- **ES7 syntax in your handler functions**
- Use async/await
- And much more!
- **Run API Gateway locally**
- Use `serverless offline start`
- **Support for unit tests**
- Run `npm test` to run your tests
- **Sourcemaps for proper error messages**
- Error message show the correct line numbers
- Works in production with CloudWatch
- **Automatic support for multiple handler files**
- No need to add a new entry to your `webpack.config.js`
- **Add environment variables for your stages**

If you'd like to learn how to setup your existing Serverless project to support ES7 async/await, use this [guide on Serverless-Stack.com](http://serverless-stack.com/chapters/add-support-for-es6-javascript.html).

Expand Down Expand Up @@ -84,6 +87,12 @@ To run a function on your local
$ serverless invoke local --function hello
```

To simulate API Gateway locally using [serverless-offline](https://github.com/dherault/serverless-offline)

``` bash
$ serverless offline start
```

Run your tests

``` bash
Expand All @@ -106,6 +115,13 @@ $ serverless deploy function --function hello

To add another function as a new file to your project, simply add the new file and add the reference to `serverless.yml`. The `webpack.config.js` automatically handles functions in different files.

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`.

### Support

- Send us an [email](mailto:[email protected]) if you have any questions
Expand Down
12 changes: 12 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# HOW TO USE:
#
# 1 Add environment variables for the various stages here
# 2 Rename this file to env.yml 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
Loading

0 comments on commit 6ba62cd

Please sign in to comment.