Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 1.73 KB

README.md

File metadata and controls

65 lines (46 loc) · 1.73 KB

NJS Micro

Build Status

A NodeJS micro framework for learning and fun.

Introduction

This lightweight web framework will teach you how popular node js frameworks like express are built. This is not intended for use in an application, this only exist for the purpose of learning how the internals of web frameworks work.

Please don't use this knowledge to create yet another NodeJS framework, we already have too many of them.

Using (NodeJS Version >= 8)

const Micro = require('./micro')

const app = new Micro({
    env: 'prod',
    templates: './templates',
    port: 3535
})

app.router.all('/', (req, res) => {
    res.end('Micro ...')
})

app.route((router) => {

    router.get('/template', (req, res) => {
        let data = {title: 'Home', test:true, items: ['Evan', 'John', 'Jane']}
        res.render('index.html', data)
    })

    router.all('/hello/:name?', (req, res) => {
        let name = req.params['name'] || 'world'
        res.end(`Hello ${name}!`)
    })

})

app.boot((err) => {
    console.log('OK');
}) 

What's included ?

  • Request routing
  • Request handling via middleware
  • Template engine with inheritance

Articles

A full step by step process of building this framework is published on my blog.