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

@spicadev/network

v0.3.0-tr3

Published

Simplify networking in Node.js with support for TLS, UDP, WS, Socket, DNS, and TCP.

Downloads

11

Readme

@spicadev/network NPM

Simplify networking in Node.js with support for TLS, UDP, WS, Socket, DNS, and TCP.

Installation

Via npm:

npm install @spicadev/network

Via Node.js:

const net = require('@spicadev/network')
const { http } = require('@spicadev/network')

Using import:

import net from '@spicadev/network'
import * as net from '@spicadev/network'
import { http } from '@spicadev/network'

Changes

  • Modified README.md
  • Bug Fix + More efficient
  • Added redirect property to HttpClientOptions
  • Removed Herobrine

Next Update (Plan)

  • Socket APIs
  • WebSocket APIs

API

net.http.Server(options?: HttpServerOptions)

Create a http server instance.

net.http.Client(...args?: HttpClientRequestArguments)

Create a http client instance.

net.http.ClientRequest(...HttpClientRequestArguments):

Promise<net.http.ClientResponse, Error>?

Create a http request

net.http.ClientResponse(

res: http.IncomingMessage | http2.ClientResponse,

data: Buffer)

Create a http response

net.http.http

Object containing http: node:http, https: node:https, http2: node:http2 | null, and get(options?: HttpChooserOptions)

Static Methods

net.http.Server.createServer(options?: HttpServerOptions): http.Server

Alias for http.Server constructor

net.http.Client.createClient(...HttpClientRequestArguments):

Promise<net.http.ClientResponse, Error>?

Alias for http.Client constructor

Prototypes

net.http.Server.route(httpMethod: string, route: string | regex,

callback: function(req, res, next)): net.http.Server

Open a route with specified http method, route/path, and callback

net.http.Server[HttpMethods](route: string | regex, callback: function(req, res, next)): net.http.Server

Open a route with specified http method, route/path, and callback (if http-method haven't implemented, use net.http.Server.route instead)

net.http.Server.hook(name: HttpHooks, callback: function): http.Server

Hook the available hooks

net.http.Server.decorate(name: string, value: any): http.Server

Decorate the server object, and req+res object per request

net.http.Server.on(event: string, callback: Function): void

Listen to event emitted by EventEmitter

Available events:

  • error
  • clientError
net.http.Server.listen(): Promise<ServerAddress, void>

Listen to the server

net.http.Server.close(): Promise<void, void>

Close the server

net.http.Client.request(...HttpClientRequestArguments): Promise<net.http.ClientResponse, Error>

Create a request

net.http.Client[HttpMethods](...HttpClientRequestArguments): Promise<net.http.ClientResponse, Error>

Create a request with specific http-method (Use http.Client.request for more flexibility)

net.http.http.get(options?: HttpChooserOptions): node:http | node:https | node:http2

Retrieve nodejs http(s) module

Types

Header

  • Object

HttpHooks

Hook 1st argument are always req: net.http.ServerRequest

Hook 2nd argument are always res: net.http.ServerResponse

  • requestIncoming(...HooksArguments)
  • preProcess(...HooksArguments)
  • error(...HooksArguments, error: Error)
  • unhandledRoute(...HooksArguments)

HttpMethods

  • get
  • post
  • put
  • patch
  • delete

HttpServerOptions

  • http -> HTTP-related options
    • ...all node:http.createServer options except IncomingMessage and ServerResponse
    • ...all node:http2.createServer options excopt IncomingMessage and ServerResponse
  • secure -> HTTP2 and HTTPS related options
    • cert: string -> Filepath targeting your ssl certificate.
    • key: string -> Filepath targeting your ssl key
  • ...ServerAddress -> Server address (excluding family)
  • ...HttpChooserOptions -> Chooser options

HttpClientOptions

  • version: number -> The http version to be use, Either 1 (http+https) or 2 (http2), default: 1
  • url: ValidURL -> URL for the request to be send to
  • body: ValidBody -> The request body, default: null
  • headers: Headers -> The request header, default: null
  • method: HTTPMethod -> HTTP method to use, default: GET
  • redirect: string -> What to do when there are redirect, either follow, manual, and error

HttpClientRequestArguments

  • 2 Arguments:
    • url: ValidURL -> URL for the request to be send to, can be placed both as 1st or 2nd argument
    • options: HttpClientOptions -> Options used, can be placed both as 1st or 2nd argument
  • 1 Argument: ValidURL | HttpClientOptions -> Either the url, or options that contain url property.

HttpChooserOptions

  • useHTTP2: boolean -> Wheter to create http2 (secure) server, throw error of http2 doesn't available, default: false
  • secure: boolean -> Wheter to create a https (secure) server, default: false

ServerAddress

  • host: string -> The server host, default for server: 0.0.0.0
  • port: number -> The server port, default for server: 3000
  • family: boolean -> Either Ipv4 or Ipv6

ValidURL

  • Native URL
  • net.utilty.Url
  • string
  • object with the same property as URL (for example: host, protocol, pathname)

ValidBody

  • Object (json-stringified)
  • String
  • Buffer
  • ArrayBuffer
  • All typed array including Uint8Array