GitHunt
JO

joseglego/node-example-app

A small node server with Sequelize & Express introduction

node-example-app

It's a step by step tutorial/commits which show the evolution from scratch to an Node API made with: express and sequelize (with postgresql). You can read the instruction or follow commit by commit the evolution of this.

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.

Prerequisites

You will need:

Installing

Database

    1. For the DB, you'll need an user with some special super powers (Login & CreateDB, and all). So, in psql run:
CREATE ROLE nodeuser;
ALTER ROLE nodeuser WITH LOGIN;
ALTER ROLE nodeuser WITH CREATEDB;
GRANT ALL ON schema public TO nodeuser;
  • 1.A Clone this repo: git@github.com:joseglego/node-example-app.git with:
git clone git@github.com:joseglego/node-example-app.git
cd node-example-app
  • 1.B Or start by your self:
mkdir node-example-app
cd node-example-app

Commits / Step by Step

0: Initial commit

Nothing special, define package.json and define first needs.

1: npm run start

Write node server/app.js everytime is boring. So, we define a npm command. Now, we'll do npm run start

2: nodemon

Turn off/on everyime we do a change in the project is boring too. So, we use nodemon instead of node (And redefine npm run start)

3: Sequelize

Check Database if you skip that part. You will need an user with some privileges.
Include requisites:

npm install sequelize sequelize-cli pg-hstore express

Once done, we can start with the database. In bash run:

sequelize-cli init
sequelize-cli db:create

P.S.: If you can't find sequelize-cli try: npx sequelize-cli or node node_modules/.bin/sequelize-cli

4: Model Enterprise

Create first model:

sequelize-cli model:create --name Enterprise --attributes name:string,countryId:string,address:string,phoneNumber:string
sequelize-cli db:migrate

5: Define first Controllers & Routes (for Enterprise)

Create first 2 routes with correspondent controllers

6: Define Modular Structure

MOST of the backend apps are showed in MVC. But, in node is common see the MVC structure for modules (Like in Python w/Django). It's becasue you can remove every module and plugin in another application.

Running the tests

No tests included yet.

Deployment

Not worked yet.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

joseglego/node-example-app | GitHunt