GitHub – JoemaNequinto/node-mysql-rest-api: 👌🏻 A boilerplate application for building RESTful APIs Microservice in Node.js using Express and Sequelize-MySQL in ES6 with JsonWebToken Authentication and
A boilerplate for building applications in Node.js using ES6 with Code Coverage. Follows Airbnb’s Javascript Style Guide.
Nội Dung Chính
Features
Installing / Getting started
Clone the repository and name it as you like.
git clone https://github.com/JoemaNequinto/node-mysql-rest-api.git<
your-project-name>
cd
your-project-name/ rm -rf .git/&&
git init git remote add origin https://github.com/<
USERNAME>
/<
REPOSITORY>
.git npm run --silent create cp .env.example .env rm README.md mv README.sample.md README.md npm install
Then fill up the prompt for modifying the package.json.
You must delete the .git folder and re-initialize it using git init
.
You must also create a new README.md. Open the new README.md then modify it depending on your project.
The above code installs the dependencies, creates an environment file, and modifies the package.json file.
MySQL create database
Simple script to create MySQL database and user.
cd
scripts/ sudo chmod 755 mysql-db-create.sh sudo ./mysql-db-create.sh<
dbname>
<
dbuser>
<
password>
You must enter the password of MySQL root user.
You must change the values of DB_NAME, DB_USER, DB_PASSWORD in .env with dbname, dbuser, password
The above code creates a MySQL database, user and password; modifies the .env file.
Developing the application
To start developing with code linter,
npm run dev
Add an access to a route for a certain role
Edit the policy.csv
file in src/lib/acl/
Add an entry:
1st column – p
2nd column – sub (role eg. admin)
3rd column – obj (resource or route eg. /users)
4th column – act (method eg. POST, GET, PUT, DELETE)
For more info, read the casbin documentation.
Making a commit
To safely follow the standards of a commit,
npm run cm
then follow the instructions.
Tests
To run tests,
npm runtest