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

your-http

v1.5.16

Published

A simple http server made for fun

Downloads

11

Readme

1. Installation

Install package using:

npm i your-http

or

yarn add your-http

2. Usage

1. Importing
JS
  const http = require('your-http');
TS
  import http from 'your-http';
2. Route Examples
JS
  const http = require('your-http');
  const router = new http.Router();

  router.get('/', (req, res, next) => {
    /* Code... */
  });

  exports.default = router;
TS
  import { Router } from 'your-http';
  const router = new Router();

  router.get('/', (req, res, next) => {
    /* Code... */
  });

  export = router;
3. How to use the Router
3.A Methods
Usage:

router.get('/', (req, res, next) => {});

Methods:

.get(), .post(), .delete(), .put(), .update()

3.B Arguments
All arguments:

req, res, next

3.B A Request (req)
All request information is stored in here.
Request object:
How to use it: Click here

| Value | Description | Type | | ------|:------------|-----:| | socket | TCP socket | Socket | | headers | Returns all headers | Object Property | | rawHeaders | All raw headers | Array | | protocol | Request HTTP protocol | string | | method | Request method | string | | url | Request endpoint | string | | body | Request body | any | | ip | Client IP | string | | query | Returns all query parameters | Object Property | | cookies | Returns all cookies | Object Property |

Only useful functions:
req.headers;

req.rawHeaders;

req.body;

req.ip;

req.query;

req.cookies;
3.B B Response (res)
All response information is stored in here.
Response object:
How to use it: Click here

| Value | Description | Type | | ------|:------------|-----:| | socket | TCP socket | Socket | | protocol | Response HTTP protocol (HTTP/1.1) | string | | statusCode | Response status code | number | | statusMessage | Response status message | string | | headers | Returns all headers | Object Property | | body | Response body | any | | server | Server name | string | | lastModified | Last change to the response | Date | | canBeSent, wasSent | Values used by the http server. | boolean | | status(number) | Change status code of the response | Function | | write(string) | Set content type to text and change response body | Function | | json(object) | Set content type to application/json and change response body | Function | | cookies | Returns all cookies | Object Property | | setCookie(name, value, settings: object) | Adds a cookie to the response headers | Function | | send(any) | Automatically sets content type and changes body | Function | | setHeaders(name, value) | Adds a response header | Function |

Only useful functions:
res.headers;

res.status(number);

res.write(string);

res.json(object);

res.send(any);

res.setCookie(name, value, settings);

res.setHeader(name, value);
DO NOT MANUALLY CHANGE RESPONSE INFORMATION. Use response functions instead ( All functions displayed above );
3.B C NextFunction (next)
If called, next router will run after the current one finishes.
Type: Function. No arguments or values.
4. How to create a server
Usage
  http.createServer(router1, router2...).listen(port, ip[optional], callback[optional]);
Example
  http.createServer(router1).listen(3000, '0.0.0.0', () => 
    console.log('🏃 on port 3000.'));
Tip: Use ip: '0.0.0.0' to get IPv4 from req.ip

3. Detailed Usage

1. Working with cookies
Getting all request cookies
...
req.cookies;
...
Adding response cookies
...
res.setCookie('name', 'value', { Settings: true });
...
2. Query & body
Getting request body
...
req.body;
...
Returning response body
...
res.functionName/* send or write or json or status */(value);
...
Getting query parameters
...
req.query;
...
Headers
Getting request headers
...
req.headers;
...
Adding a response header
...
res.setHeader('name', 'value');
...
More features coming soon!

WARNING: I did not add any security features yet.