### Table of Contents - [createApp](#createapp) - [app](#app) - [app.on](#appon) - [app.send](#appsend) - [app.error](#apperror) - [app.log](#applog) - [app.json](#appjson) - [app.pipe](#apppipe) ## createApp Create the application. Returns the `app` function that can be passed into `http.createServer`. **Parameters** - `config` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** - `config.log` **([Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean))** – Set to `false` to disable logging. Set to an object with options that are passed to [pino](https://npmjs.com/pino) and [pino-http](https://npmjs.com/pino-http) - `config.notFound` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** – Function that handlers 404 routes. Provides `req`, `res`, and `ctx` arguments just like other appa route handlers. Default: a function that sends a `404` statusCode with the message `Not found`. **Examples** ```javascript var appa = require('appa') var app = appa({ log: { level: 'info' }, // or set to `false` to disable all logging notFound: function (req, res, ctx) { return app.error(404, 'Not Found').pipe(res) } }) ``` Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** `app` ## app The request, response handler that is passed to `http.createServer`, and the object that provides methods for your app. **Parameters** - `req` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** – the http request object - `res` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** – the http response object **Examples** ```javascript var http = require('http') var appa = require('appa') var app = appa() var server = http.createServer(app) ``` ## app.on Route handler **Parameters** - `pathname` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – the route for this handler - `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** – options for the request handler - `options.parseJSON` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** – optionally disable JSON parsing of the body. Default: `true` - `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** – the route handler **Examples** ```javascript app.on('/', function (req, res, ctx) { // handle the route }) ``` ## app.send Send a JSON object as a response **Parameters** - `statusCode` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** – the status code of the response, default is 200 - `data` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** – the data that will be stringified into JSON **Examples** ```javascript var send = require('appa/send') app.on('/', function (req, res, ctx) { send({ message: 'hi' }).pipe(res) }) ``` ## app.error Send a JSON error response **Parameters** - `statusCode` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** – the status code of the response, default is 404 - `message` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – the message that will be stringified into JSON - `data` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** – additional data about the error to send in the response **Examples** ```javascript var error = require('appa/error') app.on('/', function (req, res, ctx) { error(404, 'Resource not found').pipe(res) }) ``` ## app.log Create logs using the pino module: ## app.json Parse or stringify a JSON stream using the JSONStream module: ## app.pipe Compose a stream using the pump module: