Backend API Boilerplates using PostgreSQL, Node.js, Sequelize and Express.js
This project acts as a basic Boilerplate for our API-based applications, allowing us to rapidly prototype our systems.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
This template is heavily inspired from Getting Started with Node, Express and Postgres Using Sequelize by jmuturi
If you have problems, feel freecheck the above link for reference as well.
- PostgreSQL (v12.x)
- Node.js (v12.x)
- npm (Node Package Manager) (v6.x.x)
- Git
- Sequelize
- Sequelize CLI (recommend globally)
Sequelize CLI can be installed locally for the project, however that will require you call any command using ./node_modules/.bin/sequelize
so I would suggest installing sequelize-cli globally with the -g
flag.
npm i -g sequelize-cli
You may also chose to install nodemon
, a package that will automatically restart your server (in this case your index.js
file) whenever a change is saved in the project. To do this, run
npm i -g nodemon
Installing it globally allows you to call nodemon
on any Node.js file for it to listen to changes.
A step by step series of examples that tell you how to get a development environment running.
-
Clone this repository using the Git CLI.
git clone https://github.com/niksrid/boilerplate-backend-example.git
-
Install all the dependencies for the project
npm i
-
Make sure that your PostgreSQL server is up and running on port 5432 and your USER is granted the necessary permissions and roles.
You can check out the necessary steps to do this here. Only follow this up till the CREATE DATABASE step.
-
Once you have PostgreSQL up and running, make sure you change your
config.json
file located here to reflect your appropriate URL, usrename, password and database name. Make sure thedialect
is set topostgres
. Your ideal configuration should look a little something like"development": { "username": "nikhil", "password": "password", "database": "todos-dev", "host": "127.0.0.1", "port":5432, "dialect": "postgres" },
-
To update the relevant tables and associations in your database, you will have to run
sequelize db:migrate
This will let Sequelize know that you have pending migrations that you would like to push to your PostgreSQL database. (Click here to learn about Migrations).
-
Run the Node app by calling
npm start
This will start the server on localhost:3000. You should be able to open this in your browser to see the following
{ "data": { "message": "Welcome to the beginning of nothingness." }, "diag": { "time": 1582115411811, "formatT": "2020-02-19T12:30:11.811Z", "sentBody": {} } }
You have succesfully run the app! Please make sure you follow the below guidelines before you begin development.
Add notes about how to use the system.
Add additional notes about how to deploy this on a live system.
- @niksrid - Idea & Initial work
- Hat tip to anyone whose code was used
- Inspiration
- References