Lightnode

Lightnode

Released 7 years ago , Last update 7 years ago

A nodeJS based web server framework for dynamic applications and static file serving. Lightnode is designed to be simple and understandable while delivering desirable functionality, together with the unprecedented control that nodeJS has to offer.

Designing toward a more ideal server

Lightnode is designed around the ideas of attaining a more ideal web server platform, which should be easier to manipulate and understand than our traditional servers, while still providing all the functionality that we desire for rapid development.

Node.js provides a solid base to use along our path towards a more ideal web server platform, however, as noted, it achieves this by purposely avoiding the provision of high level functionality in order to avoid the need to address the design challenge of countering the complexity and reduced flexibility inherent in introducing higher level functionality.

This means that it is up to library authors to tackle the challenge of providing a framework that provides the desired functionality while maintaining simplicity, and flexibility and ease of manipulation.

Control through a DOM inspired Hierarchy

Lightnode addresses this challenge by conceptualizing server control in a manner inspired by our browser DOM, and with the most appealing conceptually coherency.

The user creates a hierarchy of server objects prior to when the server starts listening for requests. By creating a hierarchy of server objects, each object can be customized differently, and remains conceptually separate.

A simple delegation step is added to the server objects, where users can indicate how a request event is routed down the hierarchy. It is easy to route a request to some custom code outside of the server hierarchy.

A site can be served simply with just one server, or a separate server object can be created for each sub section of the site. Servers can also be created dynamically when a request comes in, including lazily created for the case where a non-existing server is requested from the hierarchy.

The servers in the hierarchy can be instances of the user's custom subclass of the lightnode.Server control class, or of it's file server subclass lightnode.FileServer.

Functionality

Lightnode currently provides this simple hierarchical delegation framework for control, as well as add-on utility of fast static file serving with http client side caching, and a design that is easy to setup virtual hosting or any other desirable or customized setup. Much more functionality is planned to be added in future, in order to provide a platform for flexible and simple rapid development.

Product Future

Although Lightnode is a fully free and open source product, we are collecting a small fee for it here on binpress in order to fund the development so that we can provide a platform that supports developers in creating better software more easily. You can choose to pay for the product (when you mouse over "download") or just download it free, if you'd rather not support the development at this point, or if you'd just like to test it out first.

Enjoy.

Goals

  • a complete web server platform
  • good integration with and enhancement of node philosophy and usage
  • minimal / non-intrusive / non-assuming design
  • support for taming the unprecedented control node provides
  • robust static file serving with caching + virtual host + customizability
  • simple to understand handling logic
  • instructable functionality (bypass handling logic)
  • built-in desirable functionality to utilize with node such as statistics (not yet implemented), file serving, control framework etc
  • good documentation, understandable source
4.0
  • 5 1
  • 4 0
  • 3 1
  • 2 0
  • 1 0
2 Reviews Read Reviews

Pricing

14 day 14-day money-back guarantee

FREE

MIT license

The MIT license is an open-source license.

Example Techniques

Create a File Server

var mySite = new lightnode.FileServer("/home/web/mysite.com")

Send a request to be processed by a server

mySite.receiveRequest(request, response)

Delegate to another server when a request is received

mySite.delegateRequest = function(req, resp) {
    return someOtherServer
}

Create or get a child server

mySite.getChild('images')

Specify a special constructor used to create any child servers

mySite.constructChild = function(name) {
    return new MyServerType()
}

Delegate to an existing child server

// the server will automatically look for a child server for a request,
// you can control what the name it looks for the child server under.
mySite.getChildName = function(req) {
    if (req.url.startsWith('images'))
        return 'images'
    else if (req.url.startsWith('posts'))
        return 'posts'
}

// any child server that is found under the name will be delegated to,
// if it doesn't exist then no delegation is done and the server handles the request itself.

// so there is no need to do anything else except
// create the child servers before any requests come in
mySite.getChild('images')
mySite.getChild('posts')

Example

Example with delegation to a custom API handler

var http = require('http')
var lightnode = require('../lightnode')


// 1 - create and start the node ip server
var server = new http.Server(); server.listen(8081)

// 2 - create the file server for the root directory
var website = new lightnode.FileServer('/home/web/www.ngspinners.com')

// when a request comes to the ip server
server.addListener('request', function(req, resp) {

    // pass all requests to the file server
    website.receiveRequest(req, resp)

})

// specify how the delegation is done before any requests come in

// the delegateRequest function should just return the
// lightnode.HttpServer object that must emit (handle) the request, 
// or a function to execute as the request listener.
website.delegateRequest = function(req, resp) {

    // 3 - requests starting with path '/api' are sent to the api server

    if (req.url.indexOf('/api') == 0)
        return apiHandler

    // 4 - serve all other requests with this file server object

    else
        return website

}


// this is run when the given request must be handled by the API
function apiHandler(req, resp) {
    // I'm a hello world API
    var message = 'hello, world.'
    resp.writeHead(200, {
        'content-type': 'text/plain',
        'content-length': message.length
    })
    resp.write(message)
    resp.end()
}
2 licenses, starting from From » FREE View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.


Or enter your name and Email
No comments have been posted yet.