now-utilities
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

now-utilities

Utilities for serverless now^2.0

Installation

# npm
$ npm install now-utilities

# yarn
$ yarn add now-utilities

Usage

import { handle } from 'now-utilities'

export default function(req, res) {
  handle(res)
    .setStatus(200)
    .json({
      status: 'success',
      message: 'Hello World!',
    })
}

API

body(request: http.IncomingMessage)

  • returns a Promise with parsed JSON body or null

handle(response: http.ServerResponse)

  • setStatus(code: number) => { .json(), .text(), ... }

  • json(response: http.ServerResponse) => (data: JSON) => null

    • sets status code to 200
    • sets Content-Type to application/json
    • prints out json
  • text(response: http.ServerResponse) => (data: string) => null

    • sets status code to 200
    • sets Content-Type to text/plain
    • prints out text

Package Sidebar

Install

npm i now-utilities

Weekly Downloads

1

Version

0.3.1

License

MIT

Unpacked Size

5.45 kB

Total Files

5

Last publish

Collaborators

  • kocisov