Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elet

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elet

CakePHP inspired microframework in Node.js

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
increased by30.77%
Maintainers
0
Weekly downloads
 
Created
Source

Elet

CakePHP inspired micro framework in Node.js. Elet makes building web applications simpler, faster and require less code.

Installation

$ npm install elet

Get Started

Routing

Elet default routing is very similar CakePHP's default routing. You can access an action directly via the URL by putting its name in the request. You can also pass parameters to your controller actions using the URL.

URL pattern default routes:
http://example.com/controller/action/param1/param2/param3

A very basic Elet app requires app.js to initialise elet module and controller file, which receives route control. We consider a sample url route "http://example.com/articles/view".

app.js
var http = require('http');
var elet = require('elet');

elet.config({
    templateEngine: 'swig',
    controllerDir: __dirname + '/controller',
    viewDir: __dirname + '/view',
    viewExtension: 'html'
});

http.createServer(function (request, response) {
  elet.init(request, response);
}).listen(3000);

The elet application will listen on port 3000. The elet will use some configs to set the application. It will initialise the template engine, controller and view directories, custom error file etc in application. The elet supports swig, jade and ejs template engines. The npm module of template engine needs to required/installed in your application. Read more about config on guide.

Sample controller File (articles.js)
exports.view = (function () {
    var _index = function(req, res) {
        var locals = {
            title: 'Index',
            authors: ['Paul', 'Jim', 'Jane'],
            params: JSON.stringify(req.params)
        };
        res.render('index', locals);
    };
}

The URL route "http://example.com/articles/view" will hit articles controller(articles.js) and call view method. The request(req) argument provide certain useful methods and properties in view method in req.params. See more about request object injected methods and properties.

By using above files we can start to create an application.

In examples folder of this repo, there is an example usage of elet in an application.

Guide

Visit docs.

Working of elet

When user access a route(request url) like "localhost:3000/index/contact", the request first passes to "index" controller and call action method "contact". The action method then call response.render method to render a view.

Some routing examples
URLRequest MethodControllerAction Method
localhost:3000GETindexindex
localhost:3000/index/addPOSTindexadd
localhost:3000/index/contactGET/POSTindexcontact
localhost:3000/register/addGET/POSTregisteradd

API Reference

#####response.render(view, [locals object]); Renders a view and sends the rendered HTML string to the client. Parameters:

view, The template name that needs to render. If skipped or give locals as first argument in render. The method will look in view directory with action named file is present and automatically render the template.

locals, an object whose properties define local variables for the view.

If both parameters are omitted. The method will look in view directory with action named file is present and automatically render the template. #####response.json([locals object]) Sends a JSON response #####response.resWriteEnd(code, contentType, data, encode) Sends a response with respect to passed arguments status code, content type, data and encode. This method can be used to generate response with any content type as "application/json", "application/xml" etc. #####response.getParsedFileData(path, [locals object], encode) This method returns data parsed by object to create dynamic file content from template engines. The arguments will path for file path, locals the objects which parse in file for creating dynamic file and encoding is optional, which defaults to utf8 encoding.

Relases Notes

Want to improve the elet, please don’t hesitate to fork and make a Pull Request. If you have any questions, thoughts, concerns or feedback, please don't hesitate to create an issue. Your suggestions are always welcome!

License

The MIT License (MIT)

Copyright (c) 2015 Justin John Mathews justinjohnmathews@gmail.com

Keywords

FAQs

Package last updated on 05 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc