Home

Awesome

<br /> <p align="center"> <img width="25%" height="25%" src="./logo.png"> </p> <h1 align="center">Nx Serverless</h1>

The Ultimate Monorepo Starter for Node.js Serverless Applications

✅  First-Class Typescript Support<br> ✅  DynamoDB Single Table Design<br> ✅  Shared API Gateway<br> ✅  Environments Configuration<br> ✅  CORS<br> ✅  JWT Auth Middleware<br> ✅  Http Params Validation<br> ✅  Typed Proxy Handlers<br> ✅  Auto Generators<br> ✅  Localstack<br> ✅  ESLint<br> ✅  Jest<br> ✅  Github Actions

<hr />

serverless esbuild npm peer dependency version (scoped) code style: prettier GitHub license PRs Welcome Maintained

Prerequisites

Getting Started

About the App

The application contains three services:

Auth Service:

The auth service is responsible for authentication. It exposes one route for signing up:

curl --request POST 'http://localhost:3001/dev/auth/sign-up' \
--data-raw '{
    "email": "netanel@gmail.com",
    "name": "Netanel Basal"
}'

The request returns a JWT, which is used for accessing protected routes.

Users Service:

The users service is responsible for managing users. It exposes one route:

curl 'http://localhost:3003/dev/user' --header 'Authorization: token TOKEN'

The request returns the logged-in user.

Todos Service:

The todos service is responsible for managing todos. A user has many todos. It exposes CRUD routes:

// Get user todos
curl 'http://localhost:3005/dev/todos' --header 'Authorization: token TOKEN'

// Get a single todo
curl 'http://localhost:3005/dev/todos/:id' --header 'Authorization: token TOKEN'

// Create a todo
curl --request POST 'http://localhost:3005/dev/todos' \
--header 'Authorization: token TOKEN'
--data-raw '{
    "title": "Learn Serverless"
}'

// Update a todo
curl  --request PUT 'http://localhost:3005/dev/todos/:id' \
--header 'Authorization: token TOKEN' \
--data-raw '{
    "completed": true
}'

DynamoDB GUI

Download NoSQL Workbench for DynamoDB and connect to http://localhost:4566.

<p align="center"> <img width="100%" height="100%" src="./dynamo.png"> </p>

Commands

nx serve <service-name>
nx deploy <service-name>
nx remove <service-name>
nx build <service-name>
nx lint <service-name>
nx test <service-name>

// Use different enviroment
NODE_ENV=prod nx deploy <service-name> 
NODE_ENV=stg nx deploy <service-name> 

// Run only affected
nx affected:test
nx affected:deploy

Generators

// Generate a service
yarn g:service tags

// Generate handler
yarn g:handler handler-name

// Generate http handler
yarn g:http-handler create-tag

// Generate a model
yarn g:model tag
<img src="demo.gif"> <hr />

CI/CD Pipeline with Github Actions

The pipeline has been configured to run everytime a push/pull_request is made to the main branch. You should uncomment the ci.yml workflow.

Workflow Steps

By merging the pull request to the main branch, NODE_ENV is set to prod, and the deployment is done to production.

The workflow file can have as many environments as you need.

Further help

Contribution

Found an issue? feel free to raise an issue with information to reproduce.

Pull requests are welcome to improve.

License

MIT

This project is a fork of nx-serverless

<a href="https://www.flaticon.com/free-icons/monster" title="monster icons">Monster icons created by Smashicons - Flaticon</a>