This is express rest api starter kit.
This is REST api made by node.js, express.js, mysql with es6.
So you have to get node.js environment, mysql for database, know ex6 syntax.
Please install node.js and I recommend to use docker for your database.
-
Install node.js: https://nodejs.org/en/download/
-
Install Docker Desktop for MAC: https://docs.docker.com/docker-for-mac/install/
-
Install Docker Desktop for Windows: https://docs.docker.com/docker-for-windows/install/
-
Install compose: https://docs.docker.com/compose/install/
First, clone this repository into your local environment. Run followed command in your terminal.
git clone https://github.com/kyhsa93/express-rest-api-starter
Second, intall package that needed in this project.
If your node.js environment is successly downloaded, you can use node package manager.
Run followed command in your terminal.
npm install
Next up, generate mysql.
If you already have mysql in your environment, you can use that.
But if you don't have mysql database, try this process.
Install docker for your OS from link in top of this documentation.
And run followed command.
If your docker is successfully installed, you can use docker cli.
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test mysql:5.7
And then, you can connect mysql in localhost:3306, user name 'root' and password is 'test'.
Finaly, develop environment is created.
You can start api with followed command.
npm start
And if you modify code and save, you can see the process detect code changes and restart it self.
If you can use docker cli, you can build docker image.
Run followed command in project directory.
docker build -t express-rest-api-starter
docker images # list up docker images
And than you can create and run docker container using builded image.
docker run -d -p 5000:5000 express-rest-api-starter
docker ps # list up runnig container
And now you can connect api through localhost:5000.
Compose in this project is include nginx for proxy, api and mysql 5.7 for database.
Run followed command in project directory.
docker-compose up -d # build images, create and run containers in background
If you want apply your modified code into container, you can add build option.
docker-compose up -d --build # if source code is changed, rebuild image, recreate and rerun container
After use compose, you have stop and remove containers.
docker-compose down # stop and remove container in compose
And you can access database through localhost:3306.
Default database user is root and password is test.
All configuration of this project is written config.js that locations in project root path.
[https://github.com/kyhsa93/express-rest-api-starterkyhsa93/express-rest-api-starter
You can modify this file for change some config or add environment value when building docker image.
And if you use compose, you can add or modify config in .env file that located in project root or modify docker-compose.yml directly.
npm run lint # fix code automatically and print error and warn
npm run trans # transpile and generate lib
npm test # test api
Document about this project is made swagger.
Start this api without production environment, and connect localhost:5000/docs in your browser.
npm start # if process is successfully started, you can see document in your browser.