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

urlserver

v0.1.2

Published

Url routing and page serving

Downloads

11

Readme

Url Server

By Tgwizman

I made this library to make it easier on myself to prototype web servers. I ended up writting a framework around this, so this is slowly getting pushed into a solid "product". This is what I have to offer.

Simple Usage

Hosting a server using HTTP

var ur = require('urlserver');

ur.use('/url', function(input, output) {
	output.type = 'text/html';
	output.data = 'Hello world!';
});

ur.server().listen(80);

Hosting a server using HTTPS

var ur = require('urlserver');

ur.use('/url', function(input, output) {
	output.type = 'text/html';
	output.data = 'Hello world!';
});

ur.server({
	key: ur.getFile(keyPath),
	cert: ur.getFile(certPath)
}).listen({port: 443});

Some Uses

Params, Post

Url parameters are separated from the url path and put into the input. Http post requests are waited on to get post body parameter string key value pairs and are also put into the input.

ur.use('/mypage', function(input, output) {
	var data = 'Actions:';

	if (input.params.action == 'myAction1') {
		console.log('param: myAction1');
		data = ' myAction1';
	}

	if (input.post.action == 'myAction2') {
		console.log('post body ["action"] = myAction2');
		data += ' myAction2';
	}

	output.type = 'text/plain';
	output.data = data;
});

Redirecting

If you need to redirect the user to a different page, it is so simple.

ur.use('/', function(input, output) {
	output.url = '/home';
});

File Receiving

Receiving a file is super simple. Just make an on load listener, and get the data when it's ready.

ur.use('/mypage', function(input, output) {
	input.onFilesLoad = function(files) {
		var file = files.uploadedFile;
		ur.log(`Saved file "${file.name}" at "${file.path}"`);
	};
});

Data Storage

Use files as data storages, and forget the hard parts. Load a database by path, and if it doesn't exist, it will be automatically created and loaded. When you save a database, you just reference it again by the path, and all the data will be saved.

var users = ur.getDB('db/users.json');

users['Tgwizman'] = {
	favoriteColor: '#369C'
};

ur.saveDB('db/users.json');

File 'db/users.json':

{
	"Tgwizman": {
		"favoriteColor": "#369C"
	}
}

Other Uses

Logging

Keeping track of times and dates can be very important!

ur.log('Blah. Some text.');
// output:
// '[06/13/2019 02:31:04] Blah. Some text.'

Files

Accessing files can be a nuisance. These methods should make everything pretty straight forward.

// get file
// returns file text
var str = ur.getFile('path/to/file.txt');

// get file raw
// returns file without forcing utf8
var file = ur.getFileRaw('path/to/file.txt');

// set file
// sets file text
ur.setFile('path/to/file.txt', 'file\n\tdata\nhere');

// get JSON file
// returns json object from file text
var obj = ur.getJSONFile('path/to/file.json');

// set JSON file
// saves json object as text to file
ur.setJSONFile('path/to/file.json');

// deletes file
ur.delFile('path/to/file.txt');

// deletes folder
// [WARN!] will recursively delete contents by default without warning
ur.delFolder('path/to/dir/');

// rename item
ur.rename('path/to/file.txt', 'path/to/new_file_name.txt');

// make folder
// parent folders must already exist
ur.makeDir('path/to/dir');

// check if file exists
var bool = ur.exists('path/to/file.txt');

// get the mime type of a file
var str = ur.getMime('path/to/file.txt');
// returns 'text/plain'

// check if file name is windows friendly
var bool = ur.fileNameIsWindowsFriendly('file.name%20(10_10-10).extension');

Miscellaneous

Anything that doesn't fall into one of the categories above is going to be tossed here for now.

// Get network addresses
var network = ur.getNetwork();
{
	"hostname": "MyComputerName",
	"networkInterfaces": {
		"wifi": [{
			"mac": "4567:89AB:CDEF",
			"addresses": [
				"192.168.0.5"
			]
		}],
		"loopback": [{
			"mac": "0123:4567:89AB",
			"addresses": [
				"127.0.0.1"
			]
		}]
	}
}

// Get date and time with format
var date_str = ur.getDate(), // '06/13/2019'
	time_str = ur.getTime(); // '02:31:04'

function callback(data)
// HTTP GET
ur.httpGet(url, options, callback)
// HTTPS GET
ur.httpsGet(url, options, callback)
// HTTP PUT
ur.httpPut(options, body, callback)

Requests

If you would like to see anything added or anything changed, contact me.

Errors

I have made this for myself. If you are going to be using this, please know that there are many bugs and errors will happen. If you come across any, please let me know and I will try to fix them as soon as I can.