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

donode

v1.0.0-beta.8

Published

Super fast & Lightweight node framework to build RESTful APIs.

Downloads

22

Readme

donode

Superfast & Lightweight node framework for building RESTful APIs.

Simple . Flexible . High Performance . ES2015+

Enables developers to focus on writing reusable application logic in a highly modular approach.

Use donode-cli, to get started.

**NOTE: Requires node 8.0 or higher **

High Performance

Here are the performance results.

Documentation

App Structure

Create the app using donode-cli, it is as simple and modular as

  • app
    • controllers
    • middleware
    • headers.js
    • routes.js
  • env
    • development.env.js
    • production.env.js
  • app.js

Routing

One Place for all your routes and they go into app/routes.js.

A Route can be as simple as

{
  path: '/hello',
  method: 'GET',
  handler: 'HelloController@get'
}

| Property | Type | Description | | :--- | :--- | :--- | | path | string | url for the route | | method | string | can be one of GET, POST, PUT, UPDATE, DELETE. | | handler | string | format: SomeController@method Here in this format SomeController is the controller (a class) located in app/controllers directory. And method (name after @) is the name of the method in the given controller, which gets called and send response. more details availale in controllers section. |

Advanced Routing

A Route can take options like middleware, headers, children.

{
  path: '/user/{id}',
  method: 'GET',
  handler: 'UserController@get',
  middleware: ['Auth'],
  headers: ['allow-cors'],
  children: [{
  	path: '/settings',
    method: 'GET',
    handler: 'UserController@settings',
  }]
}

| Property | Type | Description | | :--- | :--- | :--- | | path | string | A route can have params in its path. syntax: {param} example: /user/{id} can respond to /user/1, /user/123 etc..| | method | string | values are not limited GET, POST, PUT, UPDATE, DELETE. can be any type of request that server can listen to. (HEAD, OPTIONS etc..) | | handler | string | A controller can be from a sub directory inside controllers directory. syntax: subdirectory/SomeController@method here in this SomeController is located in app/controllers/subdirectory. | | middleware | array or object | A Middleware is an intermediate handler which can be used to perform some pre-checks such as Auth. It is a class located in app/middleware directory and will be called before the handler method. Array Syntax: ['Middleware1', 'Middleware2'] A list of strings which are the names of the classes from app/middleware directory. When attached to a route, these will be called in the given order before the actual handler. more details availale in middleware section. Object syntax: {    all: ['Middleware1'],    only: ['Middleware2'],    children: ['Middleware3'] } -- all: attached to current the route and all its children. -- only: attached only to current route. -- children: attached to all the children, but not to current route. Note: All are optional. Any of them can be given/ignored. Order: middleware defined under all, children which are coming from parent routes (if any), then all, only of current route. | | headers | array | headers property allows to attach a set of headers that can to be sent along with the response for every request. It takes an array of stings which are defined in app/headers.js. syntax ['allow-cors', 'json-content'] Note: currently headers attached to a route will apply only to it. Not to children. Object syntax is yet to come !!!| | children | array | Routes can be nested with this attribute. This takes list of sub-routes which takes same set of above properties. example route config {   path: '/user/{id}',   method: 'GET',  handler: 'UserController@get',  children: [{     path: '/settings',      method: 'POST',      handler: 'UserController@settings'  }] } this will register the routes GET: /user/{id} POST: /user/{id}/settings |

Controllers

app/controllers: A place for all controllers of the app.

A controller is a class which inherits Controller from donode, and has the handler methods of a route.

const Controller = require('donode').Controller;

class HomeController extends Controller {
  constructor() {
    super();
  }

  get(request, response) {
    response.send({
      'app': 'works !!!'
    });
  }
}

module.exports = HomeController;

The method get(request, response) will be the handler for a route.

handler: 'HomeController@get'

It gets request, response as params.

Request

It is a native Node Request object. Along with default properties it also contains

| Property | Route | Values | | :--- | :--- | :--- | | query | /user?p1=123&p2=donode | { p1: 123, p2: 'donode' } | | params | /user/{id} | { id: 123 } | | body | - | payload sent along with request | | headers | - | headers sent along with request | | url | - | { } | | originalUrl | /user/{id} | /user/123 | | method | - | GET, POST, PUT, DELETE etc.. |

Response

It is a native Node Response object. Along with default properties it also contains

| Method | definition | Description | | :--- | :--- | :--- | | send | send([response_code,] responseObject) | It takes optional response code and a response object which whill be sent. default: 200 (OK) | | reject | reject([response_code], responseObject) | takes optional response_code and rejection responseObject. default: 401 (bad request) | | setHeader | setHeader(type, value) | takes header type and value |

Middleware

const Middleware = require('donode').Middleware;

class Auth extends Middleware {
  constructor() {
    super();
  }

  handle(request, response, next) {
    // do some auth validation here

    // if (not authorized)
    // return response.send(401, { some: 'error data' });

    // else (proceed to the controller hander)
    return next();
  }
}

module.exports = Auth;

Note:

When response.send() or response.reject() are called in a middleware, the call chain stops and handler method will not be called.

Environments

Environments for the app can be managed by creating corresponding configuration file

env/.env.js

This configuration can be used with NODE_ENV while running the app.

$ NODE_ENV= node app.js

Examples:

NODE_ENV=production node app.js
NODE_ENV=stage node app.js

Without NODE_ENV it defaults to development.env.js.