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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ts-server

v0.0.15

Published

A simple local development server.

Readme

TsServer

A simple local development server.

Install

$ npm install ts-server --save-dev

Usage

import TsServer from "ts-server"
import path from "path"
import config from "./config"

var name = "my-component"
var $server = new TsServer()
$server.set({
	root: config.paths.root,
	open: `${config.dirs.components}/${name}/preview/`,
	livereload: {
		directory: `${config.dirs.components}/${name}`,
		filter: function (file) {
			var filepos = file.replace(`${config.dirs.components}/${name}`, "")
			var sep = path.sep
			if(filepos.indexOf(sep + "dist") === 0 || filepos.indexOf(sep + "preview") === 0) {
				return true
			}
			else {
				return false
			}
		},
	},
}).start()

1 instantiate

var $server = new TsServer()

2 set options

$server.set(options)

3 start server

$server.start()

APIs

set(options)

set options before everything. Options will be merged with default options. The result us a copy of default options, so if you set again, new options will be merged with default options, not last options.

default options:

{
	host: "localhost",
	port: 8978,
	root: ".",
	open: "/",
	livereload: {
		enable: true,
		port: 9572,
		directory: ".", // only files in this directory changes causing reload
		filter: function(file) {
			// based on "directory", files in directory will be filtered for listening, return "true" to be listened, return "false" to ignore
			if(file.match(/node_modules/)) {
				return false
			}
			else {
				return true
			}
		},
		callback: function(file, current, previous) {
			// when a listened file changes
		},
	},
	middleware: [], // middleware for node http app.use. livereload is a middleware in fact
	indexes: false, // whether to display file indexes when you visit a folder
	onStart: function(app) {
		// app is an instance of express
	},
	onOpen: function() {},
	onReload: function() {},
	onRestart: function() {},
	onStop: function() {},
}

However, you can set options by passing options to constructor:

var server = new TsServer(options)
server.start()

start()

start a server after set. If the server is running, you can not start it again.

stop()

stop the running server.

restart()

stop() and then start().

reload()

Call the livereload to reload.

$server.reload()

open()

Open your local browser to open a new page. It's just an alias and improvement of open module. Just open in browser, no other feature.

$server.open(uri)

Events

onStart

When the server begin to start. before express app listen action.

$server.set({
	onStart: function(app) {
		app.use(...)
	},
})

onOpen

When server is setup, and open a browser webpage, with url

$server.set({
	...
	onOpen: function(url) {},
	...
})

onReload

After reload page.

onStop

When a server is closing.

onRestart

After a server restarted.

Generator

This application is generated by Componer. If you want to modify the source code, do like this:

npm i -g gulp-cli bower componer
mkdir your-project && cd your-project
componer init -i

componer pull {{componout-name}} -u https://github.com/{{author-name}}/{{componout-name}}.git
componer install {{componout-name}}

After you modified source code in src directory, run:

componer build {{componout-name}}

To learn more about componer, read this.