lorenzopicoli / node-api-starter

Node.js API server starter using Koa and Bookshelf

Home Page:https://lorenzopicoli.github.io/node-api-starter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node API Starter CircleCI

Dependencies codecov Code Climate

Stack

Getting started

Clone the repository:

git clone https://github.com/lorenzopicoli/node-api-starter.git

Navigate to the repo folder and install the dependencies:

npm i

Env variables will be loaded from a .env file (see Environment section)

touch .env

You can make sure the code is working by running the server on development mode:

➜ npm run dev

You should get back:

> node-starter@1.0.0 dev /Users/lorenzopicoli/WebDev/node-api-boilerplate
> NODE_ENV=development ./node_modules/.bin/nodemon index.js

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
Server running on 5000

Creating new modules

Let's call it places:

# Create the module folder
mkdir src/modules/places
touch src/modules/places/controller.js
touch src/modules/places/router.js

# Create the bookshelf model file
touch src/models/places.js

# Create the database migration file
knex migrate:make create_places_table

# Run the new migration
npm run db:migrate

Environment variables

.env example:

PORT=5000
DATABASE_URL=postgresql://localhost:5432/<db name>
AWS_BUCKET=xxxxxxx
AWS_ACCESS_KEY_ID=XXXXXXXX
AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxx
CODECOV_TOKEN=xxxxxxxxxxx
ADMIN_PASS=xxxxxxxx (admin password for seeding)
FACEBOOK_ID=xxxxxxxxx
FACEBOOK_SECRET=xxxxxxx

NPM scripts

Start the server on live mode (and migrate the database)

npm start

Start the server for development (live reload)

npm run dev

Before commit (lint and execute tests)

npm run commit

Generate documentation

npm run docs

Run tests

npm test

Documentation

API documentation is written inline and generated by jsondoc.

Example: https://lorenzopicoli.github.io/node-api-starter

Migrations & Seeding

Generate new migration

knex migrate:make migration_name

Run migrations

knex migrate:latest

Roll back migration

knex migrate:rollback

Run seeds

# development or production environment
NODE_ENV=development knex seed:run

See knex docs for details

License

MIT

About

Node.js API server starter using Koa and Bookshelf

https://lorenzopicoli.github.io/node-api-starter

License:MIT License


Languages

Language:JavaScript 100.0%