Skip to content

parayab/backend-scout

Repository files navigation

Koa REST API Boilerplate

Boilerplate for Node.js Koa REST API application with sequelize and postgresql for backend purposes.

Table of contents

  1. Requirements
    1. Node.js
    2. Yarn
    3. Postgresql
      1. Install
      2. Configure User
  2. Getting Started
  3. Commands

Requirements

If you will install something we recommend to update and upgrade before

$ sudo apt update
$ sudo apt upgrade

Node.js

# If you don't have curl
$ sudo apt install curl

# Add Node.js PPA (Personal Package Archives)
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -

# Install Node.js
$ sudo apt install nodejs

# Check version installed
$ node -v

Yarn

# If you don't have curl
$ sudo apt install curl

# Add yarn PPA (Personal Package Archives)
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

# Install yarn
$ sudo apt install yarn

# Check version
$ yarn --version

Postgresql

Install

$ sudo apt install postgresql postgresql-contrib

# Check version
$ psql --version

Configure User

First we need to create an user

$ sudo -u postgres createuser --interactive

Then we need to give a password to the new user

$ sudo -u postgres psql

postgres= alter user <username> with encrypted password '<password>';
postgres= \q

Getting Started

First you need to clone the boilerplate repository

$ git clone https://github.com/nrfreudenberg/koa-sequelize-boilerplate your-project-name
$ cd your-project-name
$ yarn
$ rm -rf .git

# If you want to start a new git repository
$ git init

Now, you need to configure your .env file. If you don't have an user and his password in postgres, check how to configure an user. If you have an user and it's password in postgres, then simply write it in .env

DB_USERNAME=username
DB_PASSWORD=password

The final step is to create the database, then just need to run migrates and seeders. The database will have the name of the variable DB_NAME in .env

$ node_modules/.bin/sequelize db:create
$ node_modules/.bin/sequelize db:migrate
$ node_modules/.bin/sequelize db:seed:all

You can start the application with yarn

$ yarn start

Now you can see the content of the homepage in localhost:3000

Also you can find the books that were created with the seeders in localhost:3000/books

It's common to not upload the .env file to the repository. To stop tracking the .env file that is in the repository you just need to run the following command:

$ git update-index --assume-unchanged .env

Commands

To run the application

# Run normally
$ yarn start

# Run the application with nodemon for development
$ yarn dev

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •