npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elet

v0.2.3

Published

CakePHP inspired microframework in Node.js

Downloads

21

Readme

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',
    webrootDir: __dirname + '/webroot',
    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 set config for the template engine and controller, view, webroot directory paths, custom error file path etc in application. The elet supports certain template engines like swig, jade, ejs etc. All supported template engines are listed here. The npm module of template engine needs to required/installed in your application. Webroot Directory serve as holding places for CSS stylesheets, images, JavaScript files etc and statically served files. Read more about config on guide.

Sample controller File (controller/articles.js)
exports.view = function () {
    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. The view method will render a template "index" from "view/articles" directory by calling res.render method. See more details about request object injected methods and properties and application structure.

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. Please refer doc for set up the example application.

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

| URL | Request Method | Controller | Action Method | |------------------------------|:----------------|------------|:---------------:| | localhost:3000 | GET | index | index | | localhost:3000/index/add | POST | index | add | | localhost:3000/index/contact | GET/POST | index | contact | | localhost:3000/register/add | GET/POST | register | add |

API Reference

response.render(view, [locals object], templateEngine)

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.
  • TemplateEngine: A string used render with different template engine than config defined default template engine. If swig is default template engine in application then this property to override to jade/ejs template engine only for corresponding request. If templateEngine is given, then we must give all other arguments that is view string and locals object in response.render method. Remember, this templateEngine given must be required before using in application.

If all arguments 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 http status code, content type, data and encode. This method can be used to generate response with any content type like "application/json", "application/xml" etc.

Parameters:

  • Code: It will be http status code. The code "200" for status "OK", "404" for "Not found" etc.
  • ContentType: The content type like "application/json", "application/xml" etc can be passed.
  • Data: This argument will be fetched data that needs to be passed to response.
  • Encode: Optional. This is a character encoding. Defaults to utf8.

#####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.

Additional Documentation

Visit additional documentation here.

Contributing

Please have look in Elet and let me know how I can improve it. Your suggestion will be highly appreciated. If any one of you like to contribute with your ideas, please do not hesitate to create an issue or make a pull request in repository. If you like to contact me, please come at [email protected].

Notes

The v0.2.0 have made change in application structure which was existed in v0.1.x.

License

The MIT License (MIT)

Copyright (c) 2015 Justin John Mathews [email protected]