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

@serverduty/httpd

v0.2.0

Published

ServerDuty HTTPD

Downloads

15

Readme

httpd

github stars npm version npm downloads

@serverduty/httpd is a straightforward, highly configurable HTTP server built with Node.js and Express. It's designed for serving static files with optional IP-based access control. Below, we'll walk you through setting up a basic "Hello World" website and running it with @serverduty/httpd.

Prerequisites

Before you begin, ensure you have Node.js installed on your system. You can download and install Node.js from here.

Step 1: Installation

First, install @serverduty/httpd globally using npm:

npm install -g @serverduty/httpd

This command makes the sdhttpd command available globally.

Step 2: Setting Up Your Website

Create a new directory for your website and navigate into it:

mkdir my-website
cd my-website

Create a simple index.html file:

<!DOCTYPE html>
<html>
<head>
  <title>Hello World</title>
</head>
<body>
  <h1>Hello World!</h1>
</body>
</html>

Step 3: Running the Server

Run sdhttpd to start serving your website:

sdhttpd

By default, the server listens on port 8000 and serves files from the www directory in the current working directory.

Step 4: Accessing Your Website

Open a web browser and navigate to http://localhost:8000. You should see your "Hello World" page.

Configuration Options

@serverduty/httpd can be configured using environment variables. Here are the available options:

  • HTTP_ROOT_DIR: The directory from which to serve files. Defaults to www in the current working directory.
  • HTTP_PORT: The port on which the server listens. Defaults to 8000.
  • HTTP_ACCESS_LIST: A comma-separated list of IP addresses allowed to access the server. If not set, all IPs are allowed.
  • HTTP_LOG_FORMAT: The format of the logs (options: combined, common, dev, short, tiny). Defaults to common.
  • HTTP_REMOTE_IP_HEADER: The name of the header containing the remote IP address. Defaults to x-forwarded-for.

Example of setting environment variables:

export HTTP_PORT=9000
export HTTP_ROOT_DIR=/path/to/your/site
export HTTP_ACCESS_LIST='192.168.1.1,192.168.1.2'
export HTTP_LOG_FORMAT='combined'
export HTTP_REMOTE_IP_HEADER='x-forwarded-for'

Then run the server:

sdhttpd

Alternatively, you can set the environment variables inline, for example:

HTTP_PORT=9000 HTTP_ROOT_DIR=/path/to/your/site sdhttpd

Step 5: Custom Error Pages

To use custom error pages, simply add 404.html, 500.html, etc., to your HTTP_ROOT_DIR. The server will serve these pages when the corresponding HTTP errors occur.

Conclusion

You've now set up a basic static website served by @serverduty/httpd. This server is suitable for quickly hosting static content with optional IP-based access control, customizable logging, and custom error pages.

License

The MIT License (MIT)

Copyright 2023 ServerDuty Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.