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

web4s

v1.1.1

Published

Branchless web hosting framework, supporting both HTTP and HTTPS.

Downloads

3

Readme

Web4s Documentation

What is web4s?

web4s is a branchless Node.js web framework focused on speed. It supports both HTTP and HTTPS.


web4s.server()

This is the main class for web4s. As it is a class, new must be invoked. In this documentation, server refers to web4s.server().


server.init()

server.init() must be called in order to use any other function of the server class. server.init() has four parameters, all have preset values: contactEmail=null, port=80, httpsMode=false, as well as cert={}. The contactEmail parameter should be any email address, example: [email protected]. As you'd probably expect, port is just the default port. The port can be specified through server.listen(), but defaults to the value in server.init(). The httpsMode parameter should be a Boolean. If it's false the cert parameter will not be used. The cert parameter can be any value accepted by options in Node's built-in https module.


server.log

server.log is the logging method of the server. It defaults to console.log.


server.domain

server.domain is the default domain expected by the server. It defaults to localhost.


server.server

server.server is the server HTTP header, defaulting to web4s.


server.raw()

server.raw() is a function with three parameters: url, execute, and domain=server.domain. The url parameter must start with /, and is a URL path. execute is a function called that gets the req, res, and url parameters passed. req and res are from the HTTP/HTTPS built-in modules. url is the domain and url parameters combined. domain just defaults to server.domain, and is the domain the server looks for.


server.get()

server.get() has seven parameters: url, body, execute=()=>{}, responseCode=200, contentType="text/html", headers={}, and domain=server.domain. As you'd expect, body is the actual thing displayed by the browser. execute is a function called after the head of the response has been written, but before it's ended.


server.getFile()

server.getFile is the same as server.get, except for one thing: body has been replaced by filename. It uses fs.creatReadStream to write a file as the body of the response.


server.post()

server.post() is the same as server.get(), but, execute is passed any form data as the parameter, data, which comes after execute's url parameter.


server.postFile()

server.postFile() is server.post() with a filename as the body parameter. It uses fs.creatReadStream to write a file as the body of the response.


server.handle404()

server.handle404() has the same parameters (excluding domain) as server.get(), and is called when the server is requested a nonexistant object.


server.listen()

server.listen() only has one parameter, port, which defaults to the value provided in server.init(). It makes the server listen for the port in the port parameter.


server.delete()

server.delete() takes two parameters, url as well as domain. It will stop listening for the path (URL+domain) provided, unless a function is called to listen again.


server.close()

server.close() takes no parameters, and closes the HTTP/HTTPS server.


Example:

const web4s=require("web4s");
const server=new web4s.server();
server.init();
server.getFile("/","./index.html");
server.listen(80);