/node-boilerplate

Boilerplate to build a starting API with Node.js, Express and PostgreSQL with Authentication JWT on ES6

Primary LanguageJavaScript

Node.js Boilerplate

This is a boilerplate to build a starting API with Node.js, Express and PostgreSQL on ES6. It is also configured with babel. The sequelize ORM is used on this project, authentication has also been set up with JWT (jsonwebtoken)

Introduction

This is a starting application for create an API with a Node.js and Express, using PostgreSQL for database and Sequelize as ORM.

Development mode

The server side Express code will be served by a node server using Nodemon which helps in automatically restarting the server whenever server side code changes.

Quick Start

First Install

If you never developed in this repo before:

  1. Clone the repository:
$ git clone git@github.com:ParmentierChristophe/node-boilerplate.git
  1. Build the base images:
$ docker-compose build app

Running the server

To run the server, you will have to start the database and run the migrations.

  1. Start database and run migrations in one command:
$ make setup-db
  1. Or start database and run migrations separately:
  • Start database (postgres):

    $ make start-db
  • Run the migrations:

    $ make migrate
  1. Then finally run the server:
$ make app

more commands

  • Seeding your database :
$ make seed
  • Undo your all migrations :
$ make migrate-undo-all

the server starts on port 8081:

http://localhost:8081

Endpoints

Swagger Documentation

Allows access to documentation

GET /api-docs

User / Authentication

Register

POST /api/register

Example request body:

{
  "email": "wwhite@breaking.bad",
  "password": "BlueSky"
}

No authentication required, returns a User

Required fields: email, password

Login

POST /api/login

Example request body:

{
  "email": "wwhite@breaking.bad",
  "password": "BlueSky"
}

No authentication required, returns a JWT

Required fields: email, password

Documentation

Folder Structure

the entrance of the application is server/index.js, on folder database All files created by Sequelize (migrations, seeds, models, config) and on folder server all files for API and for server (config, modules, utils).

Folder Database

In the database folder you already have three models and the migration files for creating three Item, List and User tables with a relationship. to create these tables, make with Sequelize:

$ make migrate

Babel

Nodemon

Express

PostgreSQL

Sequelize

Docker

Authentication

For authentication the API uses Passport and and token JWT with jsonwebtoken