Share 2 useful Nodejs modules
KP kills process based on port number, especially for PM2 cluster mode, zombie process is effective
Mount-routes automatically load routes based on paths, making development easier
Kp
KP is a tool for kill process by server port. Only with for Mac && Linux
Install
[SUDO]NPM install-g KP
Usage
Default server port is 3000, directly executing KP kills applications that use 3000 ports
Kp
Depending on a port
KP 3002
Support for sudo, because sometimes there is a problem with permissions
KP 3002-s or KP 3002--sudo
Currently Centos/ubuntu and Mac have been tested
Thank @jysperm Feedback: Fuser from Psmisc This package (Killall also in this package), Ubuntu default installation, other systems are not clear.
The reason for not using Fuser is: Fuser is not available on Mac
Mount-routes
Mount-routes = Auto Mount Express routes with Routes_folder_path
Install
NPM Install--save mount-routes
Usages
var express = require (' Express ') var app = Express () var mount = require (' mount-routes ');//simple//mount (APP);//with Path Mount (app, ' Routes2 ');//Start Serverapp.listen (23018)
Use mode 1 mount (APP);
All routes to the routes directory can be automatically mounted, with the file name as the root of the route
Like whatroutes/movies.js
It is equivalent to
var movies = require ('./config/routes/movies '); App.use ('/movies ', movies);
Use mode 2 mount (app, ' Routes2 ');
You can automatically mount all the routes below it based on the second parameter, the name of the Routing directory folder, with the file name as the root of the route
Like whatroutes2/movies.js
It is equivalent to
var movies = require ('./config/routes2/movies '); App.use ('/movies ', movies);
Summarize
Multiple routing directories can be mounted at once
Simplemount (app);//With Pathmount (app, ' Routes2 ');
But be careful not to repeat the file name, otherwise there will be problems, such as
Routes/movies.js
Routes2/movies.js
They will be mounted on the same path, which requires careful use, and future versions will consider improvements
Source
Welcome feedback and contributions
Welcome to my public number "node full stack"
Share 2 useful Nodejs modules