0.0.2 • Published 5 years ago

@refactor-later/core v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Build Status Maintainability Test Coverage

Most importantly, here are the badges. :)

@refactor-later/core

This is a fun repository to play around with node http.
It is not its aim to be a production ready framework. If you are looking for a solid solution maybe try one of my favorites:

Nest.js
If you love typescript and/or angular you will love it aswell.

Fastify
Currently the fastest lightweight framework around.

Hapi.js
Lightweight and easy to configure.

Express.js
And of course the good old express.

Installation

npm install @refactor-later

Usage

const http = require('http')
const { createApp, prepareRoutes } = require('@refactor-later/core')

const PORT = process.env.port || 3000

const routes = prepareRoutes({
  GET: [
    {
      path: '/',
      handler: (req, res) => {
        res.writeHead(200, {
          'Content-Type': 'application/json'
        })
        res.write(JSON.stringify({ hello: 'world' }))
        res.end()
      }
    },
    {
      path: '/posts/:postId?sort=date',
      handler: (req, res) => {
        const { postId } = req.params
        const { sort } = req.query
        res.writeHead(200, {
          'Content-Type': 'application/json'
        })
        res.write(JSON.stringify({ 
          postId,
          sort
        }))
        res.end()
      }
    }
  ]
})

const app = createApp({ routes })
const server = http.createServer(app)

server.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`)
})

API

TBD

createApp(config)


prepareRoutes(routes)


mergeRoutes(route1, routes2, ...)


0.0.2

5 years ago

0.0.1

5 years ago