Home

Awesome

Node.js API Starter Kit

<a href="http://www.typescriptlang.org/"><img src="https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg?style=flat-square" height="20"></a> <a href="http://patreon.com/koistya"><img src="https://img.shields.io/badge/dynamic/json?color=%23ff424d&label=Patreon&style=flat-square&query=data.attributes.patron_count&suffix=%20patrons&url=https%3A%2F%2Fwww.patreon.com%2Fapi%2Fcampaigns%2F233228" height="20"></a> <a href="https://discord.gg/GrqQaSnvmr"><img src="https://img.shields.io/discord/643523529131950086?label=Chat&style=flat-square" height="20"></a> <a href="https://github.com/kriasoft/node-starter-kit/stargazers"><img src="https://img.shields.io/github/stars/kriasoft/node-starter-kit.svg?style=social&label=Star&maxAge=3600" height="20"></a> <a href="https://twitter.com/koistya"><img src="https://img.shields.io/twitter/follow/koistya.svg?style=social&label=Follow&maxAge=3600" height="20"></a>

Node.js API Starter Kit is a project template for building Node.js backend applications optimized for serverless infrastructure such as Google Cloud Functions, AWS Lambda, Azure Functions, etc. Use it as an API server for your front-end app.

Features

<a href="https://reactstarter.com/s/1"><img src="https://reactstarter.com/s/1.png" height="60" /></a>  <a href="https://reactstarter.com/s/2"><img src="https://reactstarter.com/s/2.png" height="60" /></a>  <a href="https://reactstarter.com/s/3"><img src="https://reactstarter.com/s/3.png" height="60" /></a>


This project was bootstrapped with Node.js API Starter Kit. Be sure to join our Discord channel for assistance.

Tech Stack

Directory Structure

├──.build — Compiled and bundled output (per Cloud Function)<br> ├──.vscode — VSCode settings including code snippets, recommended extensions etc.<br> ├──api — Cloud Function for handling API requests using GraphQL.js<br> ├──auth — Authentication and session middleware<br> ├──core — Common application modules (email, logging, etc.)<br> ├──db — Database client for PostgreSQL using Knex<br> ├──emails — Email templates for transactional emails using Handlebars<br> ├──env — Environment variables for local, dev, test, and prod<br> ├──migrations — database schema migrations (Cloud SQL, Knex)<br> ├──scripts — Deployment scripts, REPL shell, etc.<br> ├──test — Unit tests and benchmarks<br> ├──views — HTML templates using Handlebars<br> └── ... — add more cloud functions such as worker, notifications, etc.

Requirements

Getting Started

Use APP_ENV environment variable to execute scripts for different environments, for example:

$ APP_ENV=test yarn db:migrate
$ APP_ENV=test yarn start

IMPORTANT: Ensure that VSCode is using the workspace versions of TypeScript and ESLint.

Scripts

Optionally set APP_ENV to local (default), dev, test, or prod before running these scripts.

How to Configure 0Auth 2.0 Login Flow

For each 3rd party identity provider that needs to be enabled for your app, you will need to obtain application credentials, often called client ID/secret.

Google

From there on, visiting http://localhost:8080/auth/google (or, opening it in a popup window) would initiate login flow via Google.

Facebook

From there on, visiting http://localhost:8080/auth/facebook (or, opening it in a popup window) would initiate login flow via Facebook.

How to Deploy

The deployment script (yarn deploy) relies on Google Cloud CLI (gcloud) tool that you can download from here. For CI/CD workflows you may need a Docker image like this one.

gcloud auth login — Authorize Google Cloud SDK (CLI) tool to use your Google account.

Create a new GCP project for your app with IDs such as example for production, and example-test for test / QA environments. Ensure that Cloud Build API and Cloud Functions API are enabled in your GCP project's settings here.

Create a Cloud SQL database instance here in the same region where your app needs to be deployed. Using a micro instance of Cloud SQL with 0.6 GB RAM should be OK for testing and low traffic websites.

Ensure that GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_REGION, PGDATABASE, PGUSER and the other environment variables are correctly set for the target deployment environment (e.g. /env/.env + /env/.env.prod for production).

Finally, compile and deploy the app by running:

Where <env> is the target environment, e.g. APP_ENV=prod yarn deploy.

How to Update

Backers

<a href="https://reactstarter.com/b/1"><img src="https://reactstarter.com/b/1.png" height="60" /></a>  <a href="https://reactstarter.com/b/2"><img src="https://reactstarter.com/b/2.png" height="60" /></a>  <a href="https://reactstarter.com/b/3"><img src="https://reactstarter.com/b/3.png" height="60" /></a>  <a href="https://reactstarter.com/b/4"><img src="https://reactstarter.com/b/4.png" height="60" /></a>  <a href="https://reactstarter.com/b/5"><img src="https://reactstarter.com/b/5.png" height="60" /></a>  <a href="https://reactstarter.com/b/6"><img src="https://reactstarter.com/b/6.png" height="60" /></a>  <a href="https://reactstarter.com/b/7"><img src="https://reactstarter.com/b/7.png" height="60" /></a>  <a href="https://reactstarter.com/b/8"><img src="https://reactstarter.com/b/8.png" height="60" /></a>

Related Projects

How to Contribute

Anyone and everyone is welcome to contribute. Start by checking out the list of open issues marked help wanted. However, if you decide to get involved, please take a moment to review the guidelines.

License

Copyright © 2016-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE file.


<sup>Made with ♥ by Konstantin Tarkus (@koistya, blog) and contributors.</sup>