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

yite

v0.0.5

Published

A web framework for Node.js called Yite.

Downloads

14

Readme

YiteWeb Framework for Node.js

A lite web framework for Node.js called Yite. This framework helps to create web pages and web applications with Javascript in Controller-View Pattern.

Installation

$ npm install yite

Get Started

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

yite.config({
  templateEngine: 'swig',
  errorFilePath: __dirname + '/views/error.html',
  controller: __dirname + '/controller',
  viewsRoutes: __dirname + '/view-paths'
});

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

The yite application will listen on port 3000. The yite will use some configs to set the application. It will set template engine, controller file path, viewRoutes file path, error file path etc in application. The yite supports swig, jade and ejs template engines. The npm module of template engine needs to required/installed in your application. All filename(controller.js, view-paths.js) can be changed to your convenience.

If no yite configs are given, it will take the defaults values, which are same as above given yite configs. Please create an empty error file(error.html) in location specified in errorFilePath config.

controller.js
module.exports = (function () {
    var _index = function(reqMethod, params) {
        return {
            test: 'testcvc',
            users: ['Gewrt', 'Jim', 'Jane']
        };
    },_add = function(reqMethod, params) {
        return {
            pagename: 'awesome people',
            authors: ['Paul', 'Jim', 'Jane']
        };
    }, _test = function(reqMethod, params) {
        return {
            pagename: 'awesome people',
            authors: ['Paul', 'Jim', 'Jane']
        };
    }, _contact = function(reqMethod, params, req, res) {
        var locals = {
            pagename: 'awesome people',
            authors: ['Justin', 'John', 'Mathews']
        };
        var data = res.getParsedFileData('views/home.html', locals);
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.end(data, 'utf-8');
    };

    return {
        index: _index,
        add: _add,
        test: _test,
        contact: _contact
    }
})();

The controller file will return method to each request. Each method will have first argument as request method(GET or POST) and second argument as parameters passed in GET and POST request. Two more arguments(request and response objects) are given optionally, if end user needs any alternation in request and response handling. For example, The http://localhost:3000/add request url will attach to add method in controller. We should specify the each method in controller file for each request(GET & POST). We can override the default controller file path in yite configs. The http://localhost:3000/contact request will be received in _contact method. This method is example of how to override default behaviour. Here res.getParsedFileData will return data with parsed object.

view-paths.js
module.exports = function (url, viewsHTMLPaths) {
  var routeHTMLs = {
    '/'     : '/views/index.html',
    '/add'  : '/views/add.html',
    '/home' : '/views/home.html'
  };
  return viewsHTMLPaths.set(url, routeHTMLs);
};

The view-paths file is used to map request route to HTML file. For example, The http://localhost:3000/add will attach to add.html HTML file in views. We can override the default view-paths file in yite configs.

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

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

Working of Yite

When user access a route(request url) like "localhost:3000/home", the request first passes to controller's method home in controller.js and return the response as json. But if we need to render a html page for corresponding route, then it needs to add map route in view-paths.js file. This will lead to parse the controller's json response into view html file using template engines. The final output will be locals object parsed in raw html.

Some routing examples

| URL | Request Method | Controller Method | View Path Map | Explanation | |------------------------|:----------------|-------------------|:----------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | localhost:3000 | GET | index |'/' : '/views/index.html' | The route will check controller have method called index. The response is raw html which will be rendered with parsing json object from method | | localhost:3000/add | POST | add | | The route will check controller have method called add. It will return response as json object as no view mapping is given. | | localhost:3000/home | GET | home |'/home' : '/views/home.html' | The route will check controller have method called home. The view html will be rendered with parsing json object from method . | | localhost:3000/contact | GET/POST | contact |'/contact' : '/views/contact.html' | The route will check controller have method called contact. The view html will be rendered with parsing json object from method . | | localhost:3000/contact | GET/POST | contact | | The route will check controller have method called contact. It will return response as json object. |

API Reference

#####res.getParsedFileData(path, [locals object], [encoding]) 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

Yite is still an experimental version.

Want to improve the yite stuff, 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 [email protected]