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

@kilcekru/dev-server

v1.1.0

Published

Simple and fast dev-server with live-reloading.\ Serves and watches one or multiple folders, reloads html on file changes.

Downloads

2

Readme

dev-server

Simple and fast dev-server with live-reloading.
Serves and watches one or multiple folders, reloads html on file changes.

DO NOT use this in production, dev-server is meant only as a tool for developing your code.

Installation

npm install --save-dev @kilcekru/dev-server

Usage

import { startServer } from "@kilcekru/dev-server";

const server = await startServer({
	root: "./public", // required; directory to serve
	port: 8080, // required; server port
	host: "localhost", // address to bind to
	delay: 200, // delay in ms after file change before reload
	injectCss: true, // inject css changes instead of reloading
	reloadOnReconnect: false, // Reload html when dev-server is restarted
	chrootRefresh: false, // Refresh html only on changes in the same or a sub-directory
	hashFiles: false, // prevent reloads if file change has same content
	ignored: undefined, // Defines files/paths to be ignored for file-watching
	middleware: undefined, // Array of middleware to add custom handling for requests
});

// address the server is listening on
console.log(server.address);

// you can manually stop the server
await server.stop();

API

startServer

startServer(options: DevServerOptions): Promise<DevServerResult>;

DevServerOptions

root (required)

Path of a directory that contains the files to serve.
Non-absolute paths are interpreted relative to current working directory.

Multiple roots can be given as Record<mountPath, directoryPath>.

  • mountPath: Url the directory will be mounted on
  • directoryPath: Path to directory

Multiple roots are independent; a change in root will not reload html served from another root.

port (required)

HTTP port the dev-server listens on.
Setting port to 0 will use a random unused port.

host

Type: string
Default: localhost

Host adress to bind to.

delay

Type: number
Default: 100

Time in ms to wait after file change before refreshing.
Very small values might trigger reloads before file write is finished.

injectCss

Type: boolean
Default: true

Don't reload on changes in css files, instead refresh only stylesheets.
Only works if css files are included with <link rel="stylesheet"> in html.

reloadOnReconnect

Type: boolean
Default: false

Reload html when dev-server is restarted.

chrootRefresh

Type: boolean
Default: false

Refresh html only on changes in the same or a sub-directory.
This is usefull to serve multiple independent webapps in folders next to each other.

hashFiles

Type: boolean
Default: false

When a file changes compare the file hash to the version before.
This prevents a refresh when a file has been written with the same content.
e.g. esbuild will write every file on every build.

This will increase CPU load especially if a lot of files are watched.

ignored

Type: anymatch-compatible definition.
Default: undefined

Defines files/paths to be ignored, absolute file path is tested, not just filename.
If a function is provided, it gets called twice per path, once with a single argument (file path), second time with 2 arguments (file path, fs.Stats object).

middleware

Type:

Array<{
	path?: string | string[];
	handler: (req: http.IncomingMessage, res: http.ServerResponse, next: (err?: unknown) => void) => void;
}>

Default: undefined

Array of middleware for custom handling of requests.

Middleware take precedence over any other route of dev-server.
Middleware functions will be called in given order if their path matches request url.

Middleware are registers using @fastify/middie.

DevServerResult

address

Type: string

Address dev-server is listening on.

stop

Type: () => Promise<void>

Function to close the dev-server.
Returns a Promise that resolves when the server is closed.