Skip to content

Latest commit

 

History

History
177 lines (121 loc) · 6.14 KB

README.md

File metadata and controls

177 lines (121 loc) · 6.14 KB

Project logo

Boilerplate Backend Template

Status GitHub Issues GitHub Pull Requests License


Backend API Boilerplates using PostgreSQL, Node.js, Sequelize and Express.js

Table of Contents

About

This project acts as a basic Boilerplate for our API-based applications, allowing us to rapidly prototype our systems.

Getting Started

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.

Prerequisites

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

Optional

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.

Installing and Running the Server

A step by step series of examples that tell you how to get a development environment running.

  1. Clone this repository using the Git CLI.

     git clone https://github.com/niksrid/boilerplate-backend-example.git
    
  2. Install all the dependencies for the project

     npm i
    
  3. 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.

  4. 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 the dialect is set to postgres. 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"
      },
    
  5. 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).

  6. 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.

Development Guidelines / Usage

Add notes about how to use the system.

Deployment

Add additional notes about how to deploy this on a live system.

Built Using

Authors

Acknowledgements

  • Hat tip to anyone whose code was used
  • Inspiration
  • References