git clone https://github.com/pemrogrammer/api-nodejs-sequalize-jwt-mysql-generator.git
-
refactor location with module aliases in
.vscode/*.code-snippets
-
split bash script generator for maintainable | flexible
-
Api repository pattern ( like laravel or lumen using a league fractal transformer etc )
-
Change all core feature with module aliases
-
use
authJwt.verifyToken
of middleware, your all request have req.user_id , make automaticaly or middleware for default request by user_id or their foreign_key like a magic on laravel -
Redis for user
-
Enhancement for bash script on GENERATE CRUD
-
Enhancement for snippet code (vscode)
-
Multiple Database
-
Flexible Database ( choose driver mysql or oracle )
-
i18n (english, indonesia, japan, arabic & china)
-
Docker File
- Generator CRUD [bash script].
- create (POST) , read (GET), update (PUT) , and delete (DELETE).
- Module Aliases.
- FILE [middleware].
- XLSX (excel) to database.
- Upload Image.
- Request.
- Authentication [ available for email & password or username & password ].
- Roles & Abilities [middleware, crud].
- Manage Users [crud].
- update data with new_password or just update other information.
- good response ( snake_case on everything's response )
- GitLens, Enumerator, Code Spell Checker
- Import Cost, Path Intellisense, Path Autocomplete
- Thunder Client, vscode-random, etc.
for snippet just type the folder name first to trigger what for todo for example if you are in auth.controller
we already known the folder is controllers
so just type cont
will trigger what todo.
alias nsc="npx sequelize-cli"
<!-- FOR MODEL -->
alias nsc-m-generate="npx sequelize-cli model:generate --name"
alias nsc-migrate="npx sequelize-cli db:migrate"
alias nsc-migrateu="npx sequelize-cli db:migrate:undo:all"
<!-- FOR SEEDER -->
alias nsc-s-generate="npx sequelize-cli seed:generate --name"
alias nsc-seeder="npx sequelize-cli db:seed:all"
alias nsc-seederu="npx sequelize-cli db:seed:undo:all"
# sometimes on seeder have an error, try with these migrate + seeder in one time execute
<!-- FOR RE-MIGRATE WITH SEEDER GENERATE ALL -->
alias nsc-migrates="nsc-migrateu && nsc-migrate && nsc-seeder"
OR
npm run db:reset
cd api-nodejs-sequalize-mysql-2022
nsc-migrates
npm run dev
chmod +x yo-coregen.sh
./yo-coregen.sh
output
1) -----------------------
2) generate migration, model, controller & router
3) generate seeder
4) -----------------------
5) migrate fresh seed
6) import view.sql
7) npx sequelize-cli db:migrate
8) npx sequelize-cli db:seed:all
9) DROP DATABASE
10) --------SERVER---------
11) RESTART SERVICE NODEJS
12) JOURNAL SERVICE NODEJS
13) show http listen
14) Quit
Please enter your choice:
/api/auth/signup
raw json
{
"email": "[email protected]",
"password": "password",
"roles": [
{
"role_id": 1 // we have 4 roles
}
]
}
/api/auth/signin
raw json
{
"email": "[email protected]",
"password": "password"
}
see more default endpoint, https://www.postman.com/yogithesymbianer/workspace/generator-api/collection/7372953-141789f0-01f9-495b-8df9-9548f9eb669e}
# | # | # |
---|---|---|
isSuperAdmin | isAdmin | isOperator |
isModerator | isModeratorOrAdmin | - |
# | # | # |
---|---|---|
checkDuplicateUsernameOrEmail | checkRolesExisted | - |
- | - | - |
# | # | # |
---|---|---|
isImage | isCsv | isExcel |
- | - | - |
package.json
"_moduleAliases": {
"@root": ".",
"@config": "src/config",
"@controllers": "src/controllers",
"@db": "src/db",
"@middleware": "src/middleware",
"@routes": "src/routes",
"@utils": "src/utils"
},
// create
app.post("/api/user",
[
authJwt.verifyToken, authJwt.isSuperAdmin,
verifySignUp.checkDuplicateUsernameOrEmail,
],
controller.user_create
);
/api/test/all
public access/api/test/user
user access/api/test/mod
moderator access/api/test/admin
admin access
x-access-token :
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiaWF0IjoxNjA2MDE1NjU5LCJleHAiOjE2MDYxMDIwNTl9.pUya-Wqm8sVmadkxfGvYL7N0Y3d-18dT3IaZtSLUMS4
#/etc/systemd/system/api-nodejs-sequelize-2022.service
Description = api-nodejs-sequelize-2022.service
After network.target = api-nodejs-sequelize-2022.service
[Service]
ExecStart=/usr/bin/npm run dev /var/www/html/api/yo-api-nodejs/server.js
Restart=on-failure
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=api-nodejs-sequelize-2022
User=nobody
Group=root
Environment=NODE_ENV=production PORT=5001
WorkingDirectory=/var/www/html/api/yo-api-nodejs
[Install]
WantedBy=multi-user.target
Then run the following to start both instances of our node application
$ systemctl start api-nodejs-sequelize-2022
The first instance will be accepting requests at port 5000, where as the other one at port 5001. If any of them crashes it will automatically be restarted.
To make your node app instances run when the server starts do the following
$ systemctl enable api-nodejs-sequelize-2022
In case there are problems with any of the following commands above you can use any of these two:
sudo systemctl status api-nodejs-sequelize-2022 -n 100 --no-pager
sudo journalctl -u api-nodejs-sequelize-2022 -n 100 --no-pager
The first line will show your app instance current status and whether it is running. The second command will show you all logging information including output on standard error and standard output streams from your instance.
Use the first command right now to see whether your app is running or whether there has been some problem starting it.
Re-deploying your app With the current setup, if we have some new application code in our repository, all you have to do is the following
cd /opt/app
git pull
sudo systemctl restart api-nodejs-sequelize-2022
sudo ufw allow 5001 // execute to allow on port
sudo ufw status verbose // status
Start your app locally using the heroku local command, which is installed as part of the Heroku CLI.
heroku local web
/node_modules
npm-debug.log
.DS_Store
/*.env
Deploy your application to Heroku After you commit your changes to git, you can deploy your app to Heroku.
git add .
git commit -m "Added a Procfile."
heroku login
Enter your Heroku credentials.
...
heroku create
Creating arcane-lowlands-8408... done, stack is cedar
http://arcane-lowlands-8408.herokuapp.com/ | [email protected]:arcane-lowlands-8408.git
Git remote heroku added
git push heroku master
...
-----> Node.js app detected
...
-----> Launching... done
http://arcane-lowlands-8408.herokuapp.com deployed to Heroku