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

pomeranian-js

v1.0.7

Published

Simple and incredibly fast framework for Node.js

Downloads

4

Readme

NPM Version NPM Downloads Linux Build Coverage Status

Pomeranian.js

Hello buddy! This is another light-weight high performance, extendable solution for you to build modern, scalable Node.js applications. It's similar to what you have already seen, to get details please read this documentation.

Installation

npm install pomeranian-js --save

or

yarn add pomeranian-js

Hello World

Just a quick example how you can start.

import { Application, Router } from "pomeranian-js";

const app = new Application();
const router = new Router();

router.addRule(
  { method: "GET", url: "/" },
  (req, res) => {
    res.json(200, { status: "Success" });
  }
);

app.useRouter(router);

app.start({
  port: 3000,
  callback: () => {
    console.log("Server is running...");
  }
});

Middlewares

Basically this is a simple way to do something with req and res objects while processing client's requests, e.g. add authorization logic before API callback runs. I call this feature as layers.

You can define layers using two ways:

Local

For specific route rule (route-level):

router.addRule(options, callback, (req, res, next) => {
  // do something with "req" and "res" objects and run callback
  next();
});
Global

Will be executed for all routes (app-level):

app.useMiddleware((req, res, next) => {
  // do something with "req" and "res" objects and run callback
  next();
});

Routes

For adding a new routing rule, you should use addRule method:

router.addRule({
  method: String, // default GET
  url: String,
  match: Object,
  query: Object,
  fileParsing: Boolean // default false
}, (req, res) => {});
Options
  • method - HTTP method, can be GET, POST, PUT, DELETE (optional)
  • url - pattern for request url (required)
  • match - patterns for special parameters in request url (optional)
  • query - patterns for query string parameters, after question mark (optional)
  • fileParsing - framework parses (if true) or doesn't parse (if false) request's body for uploaded files if Content-Type is multipart/form-data (optional)
Callback

This is how you can handle client's requests.

You can do it with typical way:

router.addRule(options, (req, res) => {
  res.statusCode = httpCode;
  res.end(content);
});

Or using our methods out of the box (res.html, res.json, res.redirect):

router.addRule(options, (req, res) => {
  res.html(httpCode, html); // return HTML content
});
router.addRule(options, (req, res) => {
  res.json(httpCode, json); // return JSON object
});
router.addRule(options, (req, res) => {
  res.redirect("/path/", 301); // redirect user to another page or website
});

Routes Examples

Just a few examples how you can use it:

router.addRule({
  url: "/{category}",
  match: {
    category: ["phones", "tablets"]
  }
}, (req, res) => {
  res.json(200, req.params);
});
router.addRule({
  url: "/{category}/{name}",
  match: {
    category: ["phones", "tablets"],
    name: "([a-z0-9]{3,50}"
  }
}, (req, res) => {
  res.json(200, req.params);
});
router.addRule({
  url: "/{category}/{name}",
  query: {
    password: "[a-z0-9]{3,50}"
  }
}, (req, res) => {
  res.json(200, { ...req.params, ...req.query });
});

Variables

While processing client's request you can get access to internal variables in req object:

  • req.clientIpAddress - client's IP address
  • req.referer - client's referrer, identifies URL that linked to resource being requested
  • req.params - URL parameters
  • req.query - query string parameters
  • req.files - name, extension, mime and content of uploaded file

Advices

We collected some advices for you, it can be useful in some cases.

Page not found

If some client's request doesn't match your routing rules, our framework will shows blank page with 404 http status. Of course for production we need more intelligent solution, so here is example how you can show your custom "not found" page:

router.addRule({
  url: "/{url}",
  match: {
    url: "(.*)"
  }
}, (req, res) => {
  res.html(404, content);
});

Just need add new routing rule for processing all requests. Important thing: this rule must be last one - just in case to overwrite previous, it's very important.

Contributing

You can help to improve my framework, here is a lot of work to do:

  • review pull requests
  • find new issue or fix existing
  • add new feature or improve old
  • update documentation

License

The Pomeranian JS framework is open-source software licensed under the MIT