Skip to content

This plugin will help you configure your response messages easily, in ExpressJS

Notifications You must be signed in to change notification settings

anubhav756/buildRes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buildRes

This plugin will help you configure your response messages easily, in ExpressJS

Usage

Specify the buildRes middleware, after specifying all the other route handlers.

app.use(index, '/');
app.use(users, '/users');

...

app.use(require('./lib/buildRes'));

Now, specify the response's configuration in the respose object, as a property buildRes, and then call next()

...

res.buildRes({
	// Configurations
});

next();

Configuration object defaults

  • status: 200
  • headers : {}
  • message: Accorging to the status code

Example

router.get('/', function(req, res, next) {
	
	// Configuration object
	res.buildRes = {
		status:404,
		headers: {
			header1: 'firstHeader',
			header2: 'secondHeader'
		},
		message: 'Sorry, not found'
	};
	
	// Call next()
	next();
});

About

This plugin will help you configure your response messages easily, in ExpressJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published