Coder Social home page Coder Social logo

stottle-uk / nx-serverless Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ngneat/nx-serverless

0.0 0.0 0.0 4.9 MB

🚀 The Ultimate Monorepo Starter for Node.js Serverless Applications

Home Page: https://netbasal.com

License: MIT License

Shell 0.02% JavaScript 0.56% TypeScript 99.42%

nx-serverless's Introduction


Nx Serverless

The Ultimate Monorepo Starter for Node.js Serverless Applications

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


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

Prerequisites

  • Docker
  • Node.js

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": "[email protected]",
    "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.

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


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

  • Checkout: The checkout action is used to checkout the source code.

  • Node setup: The setup-node action is used to optionally download and cache distribution of the requested Node.js version.

  • lint and test: The lint and test runs only on affected projects.

  • Configure AWS credentials: The credentials needed are AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and should be set as Github secrets.

  • Each branch should be prefixed with the environment name. For example, if we have a stg-feature-name branch and open a pull request to the main branch, it will set NODE_ENV to stg and deploy to this environment.

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

Monster icons created by Smashicons - Flaticon

nx-serverless's People

Contributors

netanelbasal avatar damola12345 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.