Skip to content

A rest API starter code with NodeJS, ExpressJS, SocketIO, Sequelize ORM and Postgres.

Notifications You must be signed in to change notification settings

shcherbanikolay/express-api-starter

Β 
Β 

Repository files navigation

Express API Starter Kit

Getting Started

Prerequisites

  • Postgres(>=9.4)
  • Sequelize CLI ([sudo] npm install -g sequelize-cli)

Folder Architecture

β”œβ”€β”€ mocha.conf.js
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ server
β”‚Β Β  β”œβ”€β”€ api
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ thing
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ index.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ thing.controller.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ thing.events.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ thing.helper.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ thing.model.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── thing.socket.js
β”‚Β Β  β”‚Β Β  └── user
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ index.js
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ user.controller.js
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ user.events.js
β”‚Β Β  β”‚Β Β      └── user.model.js
β”‚Β Β  β”œβ”€β”€ auth
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ auth.service.js
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ facebook
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── ...
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ google
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── ...
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ index.js
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ local
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── ...
β”‚Β Β  β”‚Β Β  └── twitter
β”‚Β Β  β”‚Β Β      └── ...
β”‚Β Β  β”œβ”€β”€ components
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ errors
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── index.js
β”‚Β Β  β”‚Β Β  └── utils
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ logger.js
β”‚Β Β  β”‚Β Β      └── responses.js
β”‚Β Β  β”œβ”€β”€ config
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ environment
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ development.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ index.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ production.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ shared.js
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── test.js
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ express.js
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ local.env.sample.js
β”‚Β Β  β”‚Β Β  └── socketio.js
β”‚Β Β  β”œβ”€β”€ index.js
β”‚Β Β  β”œβ”€β”€ routes.js
β”‚Β Β  └── sqldb
β”‚Β Β      β”œβ”€β”€ config.js
β”‚Β Β      β”œβ”€β”€ index.js
β”‚Β Β      β”œβ”€β”€ migrations
β”‚Β Β      β”‚Β Β  └── ...
β”‚Β Β      └── seeders
β”‚Β Β          └── ...
└── yarn.lock

32 directories, 81 files

Running the server

  1. Run npm install to install server dependencies.

  2. Edit the ./server/config/development.js file and enter the correct postgres DB connection variables.

  3. Run npm run dev to start the development server.

Migrations & Seeds

Migrations and seeds are placed in ./server/sqldb/migrations and ./server/sqldb/seeders respectively.

Running Migrations

To run all pending migrations, run the following command:

npm run migrate

To reverse all migrations:

npm run migrate:undo

More about Sequelize Migrations

Running Seeds

To run all seeds, run the following command:

npm run seed

To reverse all seeds:

npm run seed:undo

More about Sequelize Seeds

Testing

TODO: Add tests w. mocha vs. jest... Running npm test will run the unit tests with karma.

About

A rest API starter code with NodeJS, ExpressJS, SocketIO, Sequelize ORM and Postgres.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%