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)
This is a starting application for create an API with a Node.js and Express, using PostgreSQL for database and Sequelize as ORM.
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.
If you never developed in this repo before:
- Clone the repository:
$ git clone git@github.com:ParmentierChristophe/node-boilerplate.git
- Build the base images:
$ docker-compose build app
To run the server, you will have to start the database and run the migrations.
- Start database and run migrations in one command:
$ make setup-db
- Or start database and run migrations separately:
-
Start database (postgres):
$ make start-db
-
Run the migrations:
$ make migrate
- Then finally run the server:
$ make app
- Seeding your database :
$ make seed
- Undo your all migrations :
$ make migrate-undo-all
the server starts on port 8081:
http://localhost:8081
Allows access to documentation
GET /api-docs
POST /api/register
Example request body:
{
"email": "wwhite@breaking.bad",
"password": "BlueSky"
}
No authentication required, returns a User
Required fields: email
, password
POST /api/login
Example request body:
{
"email": "wwhite@breaking.bad",
"password": "BlueSky"
}
No authentication required, returns a JWT
Required fields: email
, password
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).
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
For authentication the API uses Passport and and token JWT with jsonwebtoken