1.0.0 • Published 7 years ago

piperjs v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

PiperJs

Modern Light-weight web server framework

Dependencies

  • NodeJs

Install via NPM

npm install piperjs --save

Usage

After you have installed PiperJs, you can include PiperJs into your project entry file by

const Piper = require('piperjs')

Create Server

To create a PiperJs server, simply instantiate the included PiperJs object

const app = new Piper()

// Use controllers as in the ./controllers folder as routes
app.apply('./controllers') // Could be any folder containing your route files
p.listen(port, bindAddress, () => {
    console.info(`Listening on port ${bindAddress}:${port}`)
})

You have to create your controllers as though they are express routes.

An example route in the ./controllers folder could be

const router = require('piperjs').router()

router.get('/', function(req, res, next) {
    res.end('The Piper')
    return
})

router.get('/hi', function(req, res, next) {
    res.end('The Piper says Hi!')
    return
})

router.get('/json', function(req, res, next) {
    res.status(200).json({message: 'The piper sends json'})
    return
})

module.exports= router

req

The request object is

res

The response object containers the following methods exposed

.status([integer])

For specifying server response code

.html([string])

For return html content. The default server response code is 200 Example

router.get('/html', function(req, res) {
    res.html('<strong>Hello, PiperJs</strong>')
})
.css([string]), .js([string])
0.0.1

7 years ago

1.0.0

7 years ago