Skip to content

Boilerplate/Starter Project for building RESTful API using Node.js, Express and Sequelize.

License

Notifications You must be signed in to change notification settings

okmttdhr/express-rest-api-2018

Repository files navigation

Express Rest API 2018

Boilerplate/Starter Project for building RESTful API using Node.js, Express and Sequelize.

(Influenced by express-rest-es2017-boilerplate).

Features

Pre Requirements

Getting Started

$ git clone https://github.com/okmttdhr/express-rest-api-2018.git
$ cd express-resr-api-2018
$ cp .env.sample .env
$ yarn docker:build
$ yarn docker:dev

Now your app is running.

$ curl -X POST -H 'Content-Type:application/json' -d '{"title": "ttttt", "body": "bbbbb"}' http://localhost/posts
{"message":"OK","id":1}
$ curl -H 'Content-Type:application/json' -X GET http://localhost/posts
{"posts":[{"id":1,"title":"ttttt","body":"bbbbb","created_at":"2018-06-09T00:43:21.000Z","updated_at":"2018-06-09T00:43:21.000Z"}],"total_count":1,"current_page":1,"total_page":1}

Testing

Run migration if you haven't yet.

$ docker exec -it expressrestapi2018_app_1 /bin/bash
root@id:/app# NODE_ENV=test yarn db db:migrate

All the test's command here.

$ docker exec -it expressrestapi2018_app_1 /bin/bash
# all the tests
root:/app# yarn test
# all the unit tests
root:/app# yarn test:unit
# only target file's test
root:/app# yarn test:unit:target ./path/to/file.js
# only target file's test with Node debugging client
root:/app# yarn test:unit:target debug ./path/to/file.js
# linting
root:/app# yarn test:lint
# flow
root:/app# yarn flow

Database

Connect to MySQL

$ docker exec -it expressrestapi2018_db_1 /bin/bash
root@id:/\# mysql -u root -pdocker
mysql> show databases;
+-----------------------------------+
| Database                          |
+-----------------------------------+
| information_schema                |
| express_rest_api_2018_development |
| express_rest_api_2018_test        |
| mysql                             |
| performance_schema                |
+-----------------------------------+
4 rows in set (0.00 sec)

Creating Model and Migration

License

MIT