Step by step guide to building a Serverless service with Node.js.
- Prerequisites
- Repo Structure
- Guide
- Step 1 - Serverless Setup
- Step 2 - Creating the Function
- Step 3 - Add Typescript support
- Step 4 - Adding unit tests
- Step 5 - Configure API Gateway endpoint
- Step 6 - Write the Lambda function part 1 - node-readability
- Step 7 - Write the Lambda function part 2 - upndown
- Bonus Round
Have a quick read of the prerequisites below, then jump into Step 1!
This project uses Amazon Web Services (AWS) to host the service. You can build and test the code without an account, but it's much more fun to deploy it! If you don't qualify for the AWS free tier, this project will cost no more than a few pennies. You will use the Lambda and API Gateway services.
You'll need Node.js installed for this project. At the time of writing, AWS Lambda uses version 4.3.2 of Node , so I recommend you use the same. I use nvm to manage Node versions - there are alternatives listed for Windows users in the nvm README.
This project uses Typescript (a typed superset of JavaScript.) An editor with Typescript support is helpful when coding with Typescript. Some options include:
- Visual Studio Code
- Atom with the atom-typescript package.
- Sublime Text with the Typescript Plugin
- Some others from Microsoft.
To follow this guide, simply clone this repo and follow the tutorial steps. If you get stuck at ay point, there is a branch that represents the project at the end of each step. For example, the Step 1 branch represents what your project should look like (minus gitignored files) at the end of Step 1.
If you check out a branch, be sure to run
npm install
to make sure that all dependencies are installed and the code is compiled.