I'm tired of writing boilerplate codes for an MVC design pattern in my Express project. So I decided to create a generator for it. 🚀🚀
The package for this tool, I named it VYNL, it is published in npm and you can start using it in your project.
$ npm install vynl
Create an empty express project, then type in
$ npx vynl init
What it does for you, is simple, it makes out your project directory like so:
.
|--auth
| └──auth.js
|--config
| └──config.json
|--docs
| |--paths
| | |--index.js
| | └──users.js
| └──schemas
| |--index.js
| └──users.js
|--migrations
|--models
|--routes
|--app.js
└──swagger.js
It also creates these things out of the box for you:
- A Users MVC (with Sequelize Model)
- Basic authentication using jsonwebtoken
- Swagger Documentation for the API routes.
Next, Adjust your project database configuration in config/config.json
Since the generator will only write codes for you, You are still required to install the packages needed to run the project yourself.
$ npm install sequelize jsonwebtoken swagger-ui-express mysql2
if you are using other database than mysql, check here
Then to generate a new MVC simply use:
$ npx vynl generate:api -m <model_name> -f <model_fields>
model_fields syntax: : and comma separated for the next field. Ex. name:string,birth_date:string,email:string,password:string
It also allows you to only generate a part of the MVC (ex. only the Model).
- Generate Model
$ npx vynl generate:model -m <model_name> -f <model_fields>
- Generate Controller
$ npx vynl generate:controller -m <model_name>
- Generate Route
$ npx vynl generate:route -r <route_name>
- Generate Swagger Doc
$ npx vynl generate:swagger -m <model_name> -f <model_fields>
And that's it. I hope this tool can help you in your next Express project.
Cheers 🍷
Top comments (2)
Checkout tsed.io/
This is lit 🔥🔥. Thank you for sharing 😁