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

nodable

v0.0.3

Published

A compact, high-performance and full-featured web framework based on nodejs.

Downloads

7

Readme

Nodable

A compact, high-performance and full-featured web framework based on nodejs. The features include:

  • [x] Application context
  • [x] Middlewares like Koa.js
  • [x] Built-in static service
  • [x] Built-in routing service
  • [x] Built-in template engine

Installation

npm i nodable

Get Started

const app = require("nodable");

app
  .serve("/assets/*")
  .engine({
    root: "template",
    imports: { globalName: "" },
  })
  .on("error", (err, ctx) => {
    console.error(err);
    ctx.body = {
      status: ctx.status,
      message: ctx.body,
    };
  })
  .use(async (ctx, next) => {
    ctx.custom = "xxxx";
    await next();
  })
  .get("/", async (ctx) => {
    console.log(ctx.query);
    console.log(ctx.params);
  })
  .listen();

API Reference

Methods

  • app.serve(path) Serve static resources with the given path. It's the syntactic sugar for get routing, so the path must starts with "/".
  • app.engine(options) Enable template engine with options { root, imports }.
  • app.on("error", function) Custom unified error handling.
  • app.use(function) Add a middleware like koa.js.
  • app.get(path, [tmpl,] function) Add dynamic route including post, put, delete and other standard request methods, it will auto-render template if tmpl parameter exists.
  • app.listen([port]) Create and start an application server on the specified port.
  • app.callback() Return a request handler for node's native http server.

Context

Properties

  • ctx.params Get params in route path, wildcard supports
  • ctx.query Get params in query string
  • ctx.method Get request method
  • ctx.path Get request path
  • ctx.url Get request full href
  • ctx.protocol Get request protocol
  • ctx.host Get request host
  • ctx.hostname Get request hostname
  • ctx.origin Get request origin
  • ctx.headers Get headers object
  • ctx.cookies Get cookies object
  • ctx.status Get response status code
  • ctx.body Get response body
  • ctx.request Get native request
  • ctx.response Get native response
  • ctx.status= Set response status code
  • ctx.body= Set response body

Methods

  • ctx.get(name) Get request headers by name
  • ctx.set(name, value) Set response headers
  • ctx.cookie(name, value[, options]) Set cookies
  • async ctx.json() Get request body in json
  • async ctx.text() Get request body in text
  • async ctx.buffer() Get request body in buffer
  • ctx.redirect(url[, status]) Redirect url with status default 301
  • ctx.view(path, data) Render template file, only if engine enabled.
  • ctx.render(path, data) Render template text, only if engine enabled.
  • ctx.throw(message, status) Throw an error with status code

Route Syntax

  • /static static route
  • /* Wildcard route, it will return wildcard variable in ctx.params
  • /:user
  • /:user?
  • /:user(\\d+)

Template Syntax

  • {{ }} Evaluate code snippet in javascript. Note that the variables do not need to be declared. ex. {{ result = 60*60; }}

  • {{= }} Interpolation. ex. {{= username }}

  • {{? }} {{?? }} {{? }} Conditional statement. ex.

{{? gender == 0 }}
  <div>Female</div>
{{?? gender == 1 }}
  <div>Male</div>
{{?? }}
  <div>Unknown</div>
{{? }}
  • {{~ }} {{~ }} Iterative statement. ex.
<ul>
{{~ users:user:index }}
  <li>{{= index+1 }} - {{= user.name }}<li>
{{~ }}
</ul>
  • {{> }} Block placeholder.
  • {{< }} Block content definition.
{{> content }}

{{< content }}
  <h1>Hello.</h1>
{{< }}
  • {{@ }} Partial including in layout mode. You must be rendered by view(file, data) method.
// index.html
{{@ header.html }}

// header.html
<h1>Hello.</h1>