sw-text

0.0.1 • Public • Published

sw-text

Convenience middleware for sending text. Adds a .text() method to the res object which sends back text with a Content-Type of text/plain.

Install

npm install sw-text

Example

var text = require('sw-text');

// With express
app.use(text);

// or use as inline middleware
app.get('/example/page', text, function(req, res) {
	if(req.query.n) {
		res.text('Nothing', 404); // The status code can be passed in place of options
	} else {
		res.text('Some text');
	}
});

API

res.text(body, [options])

  • body - String or buffer holding the response body
  • options - Options object, optional
  • code - Status code, defaults to 200
  • charset - Character encoding, defaults to utf-8

Readme

Keywords

Package Sidebar

Install

npm i sw-text

Weekly Downloads

1

Version

0.0.1

License

WTFPL

Last publish

Collaborators

  • download