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

@ncpa0cpl/goserve

v1.0.3

Published

A simple static file server written in Go.

Downloads

11

Readme

goserve

A very simple http static file server

Build & Install

Install via npm

npm i -D @ncap0cpl/goserve

Build yourself

Clone the repo

git clone https://github.com/ncpa0cpl/goserve

Build the binary

go build -o ./goserve

Install the program in your PATH Copy the binary to a bin directory (assuming ~/.local/bin is in your PATH)

cp ./goserve ~/.local/bin

Usage

Usage: goserve [options] [directory]

Options:
  --help              Print this help message.
  --loglevel <level>  The log level. Default: info
  --port <port>       The port to serve on. Default: 8080
  --redirect <url>    Redirect all unmatched routes to a specified url.
  --spa <filepath>    Specify a file to send for all unmatched routes.
  --chunk-size <KB>   The size of chunks when streaming. Default: 2048KB
  --no-streaming      Disables the server ability to process Range requests and sending partial content.
  --compress          Compress responses using the GZip algorithm.

Hot Module Reload
  --aw           Alias for '--watch --auto-reload'
  --watch        When enabled, server will send fs events when files are changed. To listen to these add event listeners to `window.HMR` on client side.
  --auto-reload  Automatically inject a script to html files that will reload the page on a 'watch' change event.

Cache Headers Options
  --maxage <seconds>   The max-age value to set in the Cache-Control header.
  --nocache            Require browsers to re-validate etag on each resource load.
  --noetag             Disable ETag generation.

Server Cache
  --cache:max <MB>     Maximum size of all files in the cache. Default: 100MB
  --cache:flimit <MB>  Maximum size of single file that can be put in cache. Default: 10MB

To serve files from the public directory of the current directory on port 8000:

goserve --port 8000 ./public

Node API

Goserve can also be imported in a Node script and spawned using a provided function.

import { serve } from '@ncap0cpl/goserve';

const childProcess = serve("path/to/directory", {
  port: 3000
});

Options

Auto-reload

When auto-reload is enabled, either via --auto-reload or --aw flag, a script tag will be injected to every ".html" file that will reload the page every time that file is changed. Note that the --auto-reload flag must be used alongside the --watch flag.

Watch mode

When watch mode is enabled, either via --watch or --aw flag, to every ".html" file a script tag will be injected enabling listening to file changes within the hosted directory.

Listening to these changes can be done by adding event listeners to window.HMR object:

HMR.onChange((event) => {
  console.log(`file ${event.file} has changed`);
});

HMR.onCreate((event) => {
  console.log(`file ${event.file} has been created`);
});

HMR.onDelete((event) => {
  console.log(`file ${event.file} has been deleted`);
});

HMR.onRename((event) => {
  console.log(`file ${event.oldFile} has been renamed to ${event.file}`);
});

HMR.onCurrentPageChange((event) => {
  console.log(`current page's file has changed`);
});