Boilerplate for Node.js Koa REST API application with sequelize and postgresql for backend purposes.
If you will install something we recommend to update and upgrade before
$ sudo apt update
$ sudo apt upgrade
# 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
# 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
$ sudo apt install postgresql postgresql-contrib
# Check version
$ psql --version
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
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
To run the application
# Run normally
$ yarn start
# Run the application with nodemon for development
$ yarn dev