Share 2 useful Nodejs modules

Source: Internet
Author: User
Tags server port

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

    • Https://github.com/i5ting/kp

    • Https://github.com/moajs/mount-routes

Welcome to my public number "node full stack"


Share 2 useful Nodejs modules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.