Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
swyxio authored Jan 10, 2020
1 parent 7a7d558 commit ee88c52
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ If you need local-only environment variables that you don't place in `netlify.to
If you are new to writing Lambda functions, this section may help you. Function signatures should conform to one of either two styles. Traditional callback style:

```js
// legacy callback style - not encouraged anymore, but you'll still see examples doing this
exports.handler = function(event, context, callback) {
// your server-side functionality
callback(null, {
Expand All @@ -149,13 +150,15 @@ exports.handler = function(event, context, callback) {
or you can use async/await:

```js
// modern JS style - encouraged
export async function handler(event, context) {
return {
statusCode: 200,
body: JSON.stringify({ message: `Hello world ${Math.floor(Math.random() * 10)}` })
};
}
```
> :warning: The above example only works with `netlify-lambda` because [it uses ES module syntax](https://community.netlify.com/t/async-await-lambda-function-example/6976/3)! If you get `Function invocation failed: SyntaxError: Unexpected token 'export'.` errors, this is why.
For more Functions examples, check:

Expand Down

0 comments on commit ee88c52

Please sign in to comment.