Node.js project template pre-configured with TypeScript, PostgreSQL, login flow, transactional emails, unit tests, CI/CD workflow.
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.
local
, dev
, test
, and prod
environmentsThis project was bootstrapped with Node.js API Starter Kit.
Be sure to join our Discord channel for assistance.
├──
.build
— Compiled and bundled output (per Cloud Function)├──
.vscode
— VSCode settings including code snippets, recommended extensions etc.├──
api
— Cloud Function for handling API requests using GraphQL.js├──
auth
— Authentication and session middleware├──
core
— Common application modules (email, logging, etc.)├──
db
— Database client for PostgreSQL using Knex├──
emails
— Email templates for transactional emails using Handlebars├──
env
— Environment variables for local
, dev
, test
, and prod
├──
migrations
— database schema migrations (Cloud SQL, Knex)├──
scripts
— Deployment scripts, REPL shell, etc.├──
test
— Unit tests and benchmarks├──
views
— HTML templates using Handlebars└── ...
— add more cloud functions such as worker
, notifications
, etc.
git clone -o seed https://github.com/kriasoft/node-starter-kit.git
.local
, dev
, test
, and prod
environments (./env
).yarn install
yarn db:create
yarn start
, it will become available at http://localhost:8080.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.
yarn start
— Launches the app in development mode on http://localhost:8080
yarn build
— Compiles and bundles the app for deploymentyarn lint
— Validate code using ESLintyarn tsc
— Validate code using TypeScript compileryarn test
— Run unit tests with Jest, Supertestyarn repl
— Connect to the database using Knex REPL shellyarn psql
— Connect to the database using PostgreSQL CLIyarn db:create
— Create a new databaseyarn db:version
— Check the current version of the databaseyarn db:migrate
— Migrate database schema to the latest versionyarn db:rollback
— Rollback the latest migrationyarn db:seed
— Seed database with sample / reference datayarn db:reset
— Re-apply the latest DB schema migration fileyarn update-types
— Generate strongly typed data models from database schemaOptionally set APP_ENV
to local
(default), dev
, test
, or prod
before running these scripts.
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.
http://localhost/auth/google/return
as the callback URLGOOGLE_CLIENT_ID
, GOOGLE_CLIENT_SECRET
environment variables./env/.env.*
for each environment that you need.From there on, visiting http://localhost:8080/auth/google
(or, opening it in a popup window) would initiate login flow via Google.
http://localhost/auth/facebook/return
as the callback URL for the login flowFACEBOOK_APP_ID
, FACEBOOK_APP_SECRET
variables found in env/.env.*
From there on, visiting http://localhost:8080/auth/facebook
(or, opening it in a popup window) would initiate login flow via Facebook.
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:
yarn build
— Compiles the app into the .build
folderAPP_ENV=<env> yarn db:migrate
— Migrates database (schema) to the latest versionAPP_ENV=<env> yarn deploy
— Deploys the app to Google Cloud Functions (GCF)Where <env>
is the target environment, e.g. APP_ENV=prod yarn deploy
.
yarn set version latest
— Bump Yarn to the latest versionyarn upgrade-interactive
— Update Node.js modules (dependencies)yarn pnpify --sdk vscode
— Update TypeScript, ESLint, and Prettier settings in VSCodeAnyone 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.
Copyright © 2016-present Kriasoft. This source code is licensed under the MIT license found in the
LICENSE file.
Made with ♥ by Konstantin Tarkus (@koistya, @koistya">blog)
and contributors.