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

z-http

v1.1.42

Published

handle all routs for the app and deliver all type of files

Downloads

259

Readme

this is a part of ZadaheaD's owner core tools for easier much more efficiant way to work with HTML, CSS, and Javascripts

look at z-views, if you want a lightweight "ejs like" server-side rendering engine

I never liked working with ejs, or these kind of tools cos I find them very messy, and I always liked working as clean and as seperated as possible. so in this project, I will use the same logic as ejs but with much cleaner way to handle HTML files and manipulate JS objects.

About - Installation

Install z-UIKit, A server side rendering Framework aimed to make front-end development much smoother and flexible with one code base to handle all.

This documentation is designed to start a project from scratch with nothing but npm init

the first thing to install is the http-server for the project.

z-http

z-http is designed for building web applications and APIs.

To install, run npm install for your package.json dependencies:

npm install z-http

to run the server

var http = require('z-http');
http.start(3000, function (route, method) {
    return (data, callback) => {
        callback(`Hello World`);
    }
}, {
//params will go here
});

response for: http://localhost:3000/

Hello World

to get information about method, route, payload or querystring use:

var http = require('z-http');

http.start(3000, function (route, method) {
    return (data, callback) => {
        callback(`
            A ${method.toUpperCase()} request
            for <b>/${route}</b> route
            has been called. <br />

            payload: ${JSON.stringify(data.payload)} <br />
            querystring: ${JSON.stringify(data.querystring)}
        `);
    }
}, {});

response for: http://localhost:3000/home?hello=world

A GET request for /home route has been called.
payload: {}
querystring: {"hello":"world"}

In order to validate request, you can add validation parameter

var http = require('z-http');

http.start(3000, function (route, method) {
    return (data, callback) => {
        callback(`
            A ${method.toUpperCase()} request
            for <b>/${route}</b> route
            has been called. <br />

            payload: ${JSON.stringify(data.payload)} <br />
            querystring: ${JSON.stringify(data.querystring)} 
        `);
    }
}, {
    validation: function (data, callback) {

        this.data = data;
        this.callback = callback;

        this.trig = () => {
            //=>> validate request here
            console.log("headers", data.headers);
            console.log("cookies", data.cookies);

            console.log("querystring", data.querystring);
            console.log("payload", data.payload);
 
            //if valid
            //callback(data);

            //if not valid
            callback(data, {}, errorRoute);
        }
    }
});

const errorRoute = (data, callback) => {
 //fallback function for error requests
 callback("this is an unauthorized request", http.STATUS.UNAUTHORIZED)
}

In order to pass decoded data (like user info) to the request, you can pass it in the validation section

var http = require('z-http');

http.start(3000, function (route, method) {
    return (data, callback) => {
        callback(`
            A ${method.toUpperCase()} request
            for <b>/${route}</b> route
            has been called. <br />

            decoded data: ${JSON.stringify(data.decode)}
        `);
    }
}, {
    validation: function (data, callback) {

        this.data = data;
        this.callback = callback;

        this.trig = () => {

            //pass info from second param
            callback(data, {
                id: 1,
                name: "Mosh"
            });
        }
    }
});

Additional params you can use to define server

http.start(3000, function (route, method) {
    return (data, callback) => {
        callback(`Hello World`);
    }
}, {
   public: 'assets', //public folder for js, css etc - this will load files automatically without routes
   maxFileSize: 500 * 1024 * 1024, //allowed file size is set to 500 MB
   onresponse: (resp, status) => {
      //event triggered for each response sent
      console.log("resp", resp); //the response value
      console.log("status", status); //the response status code
   },
   userBuffer: true, //use buffer (default: false)
   contentTpe: http.CONTENT_TYPE.JSON //set content type (default: text/html)
});

CONST Types

http.STATUS = {
  OK: 200,
  NO_CONTENT: 204,
  REDIRECT_URI: 308,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  CONFLICT: 409,
  TOO_MANY: 429
};
http.CONTENT_TYPE = {
  HTML: 'html',
  CSS: 'css',
  JS: 'js',
  ICO: 'ico',
  JPEG: 'jpg',
  PNG: 'png',
  WOFF2: 'woff2',
  WOFF: 'woff',
  TTF: 'ttf',
  EOT: 'eot',
  SVG: 'svg',
  JSON: 'json',
  XLSX: 'xlsx'
}