Giter VIP home page Giter VIP logo

norajs's Introduction

Nora.js Build Status

Sweet, simple express services

A sweet, simple, express-oriented framework for quickly hammering out ES7-style services. Convention over configuration, but hardly any of either, Nora is aware of a Server, Configurations and Services โ€“ with the server representing your app.

In terms of lifecycle, Nora apps typically do the following:

  • Spin up a Server, which can configure Express as needed
  • Add Configurations, potentially instantiating DB connections, wiring up Express routes, etc
  • Add Services, which do the business logic of your application
  • Start express by listening on the designated port (5000 by default)

Configurations have a two-step lifecycle, Configuration.preConfigure and Configuration.postConfigure respectively. The difference between the two is that the latter is called after all configs have had their Configuration.preConfigure methods run and all services have had their Service.configure methods run โ€“ allowing services to be retrieved by name.

A simple example:

svc/DummyService.js:

const nora = require('norajs')
class DummyService extends nora.Service {

  postConfigure(server){
    this.logger.info('Configured!')
  }

  doSomething(){
    return 'Dummy service did something!'
  }
}

module.exports = new DummyService()

app.js:

const nora = require('norajs')
class DummyRouter extends nora.Configuration {

  postConfigure(server, config, idx){
    const { app } = server         
    const { DummyService } = server.named

    const router = nora.Router()
    router.get('/dummy', async (req, res, next) => {
      res.send({name: 'Jimbo Jones', message: DummyService.doSomething() })
    })

    app.use('/test', router)
  }
}

const server = new nora.Server({
  basePath: __dirname,
  nora: { autoscan: true }
})
server.addConfig(new DummyRouter())
server.start()

Note that we specified autoscan: true on the server's nora property, allowing nora to scan both the ./config and ./svc folders for Services and Configurations respectively.

norajs's People

Contributors

dwelch2344 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.