Getting Started

Getting started using the Octoris Node HTTP Framework

Installation

You can install Octoris via npm with

$ npm i octoris

Core API

Octoris returns an object back which I like to consider the core api

{
  listen,
  methods,
  response,
  router,
  utils,
  debug
}

Full Usage Example

index.js
const { listen } = require('octoris')
const routes = require('./routes')

listen({ port: 3000 }, routes)
  .then(addr => console.log(`Server Listening on ${addr}`))
  .catch(console.error)
routes.js
const { router, response, methods } = require('octoris')
const { send } = response
const { route, fixed, composeRoutes } = router
const { GET } = methods

function homeHandler () {
  return send(200, 'Hello Home!')
}

function aboutHandler () {
  return send(200, 'Hello About!')
}

const home = route([fixed('home')], [
  GET(homeHandler)
])

const about = route([fixed('about')], [
  GET(aboutHandler)
])

module.exports = composeRoutes({ logger: true }, [about, home])

And now you have a very simple starting server to work with!

Last updated