- Koa2
- Knex
- Bookshelf
- PostgreSQL
- Node > 7.6.0
- Babel (stage-0)
- Mocha
- JSONDoc
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
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
.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 start
npm run dev
npm run commit
npm run docs
npm test
API documentation is written inline and generated by jsondoc.
Example: https://lorenzopicoli.github.io/node-api-starter
knex migrate:make migration_name
knex migrate:latest
knex migrate:rollback
# development or production environment
NODE_ENV=development knex seed:run
See knex docs for details
MIT