Node.js version >=4 required. If you have nvm
installed use nvm use
to select node.js version from .nvmrc
file.
- Local project dependencies (
npm install
) - Global dependencies:
mocha
for running tests,knex
for running migrations
Install MySQL (on Mac, using homebrew is recommended, brew install mysql
) and start the database server (mysql.server start
)
Create the databases (dev and test) and the application DB user from MySQL CLI (mysql -u root
):
CREATE DATABASE food;
CREATE DATABASE food_test;
GRANT ALL PRIVILEGES ON food.* TO 'food'@'localhost' IDENTIFIED BY 'food';
GRANT ALL PRIVILEGES ON food_test.* TO 'food'@'localhost' IDENTIFIED BY 'food';
And then create the schema:
npm run migrate
And insert seed data:
npm run seed
Start the server:
npm start
Since the npm start
runs the pm2 daemon, make sure you kill it with npm run stop
before starting the server again. Otherwise an 'EADDRINUSE' error will happen. ^C
while running npm start
does kill the watching and logs tasks, it doesn't kill the server process though.
Available npm scripts:
npm run migrate:dev
- Execute dev migrations onfood
databasenpm run migrate:test
- Execute test migrations onfood_test
databasenpm run migrate
- Execute both dev and test migrationsnpm run seed
- Insert seed data in the DBnpm test
- Run server testsnpm start
- Applies migrations and starts the API server daemon and logsnpm run watch
- Applies migrations and starts the API server daemonnpm run logs
- Shows server process' logsnpm run stop
- Kills server process
One of the migrations creates an application user admin
with password admin
in the database.