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

client_require

v0.4.0

Published

NPM modules packaged with a CommonJS module interface and served synchronously to the client.

Downloads

27

Readme

Client Require

This library allows you to run your Node.JS application on the client side using standard CommonJS module syntax. It supports loading client files from dependency NPM packages and easily branching between client and server modules when necessary.

In development mode, loaded package files will present error messages in the browser which match the filename and line number of the related server-side file.

In production mode, packages will be placed within a single closure with no leaking scope.

Usage

In your package.json, list your dependencies as you normally would, and add an additional configuration field called "client_dependencies", which is a list of module names.

{
	"main": "app.js",
	"dependencies": {
		"client_require": "*",
		"uuid-v4": "*"
	}
	"client_dependencies": ['uuid-v4']
}

Type npm install as usual to install the dependencies.

In your Node.js app, pass an instance of your HTTP server to fhtagn:

var client_require = require('client_require');

var http = require('http');
var app  = http.createServer(function (req, res) {
	var out = "<html><head>";
	client_require.getScripts(function(e, srcs) {
		for (var i in srcs) {
			out += '<script src="'+srcs[i]+'"></script>';
		}
		out += "</head><body>Ia! Ia!</body></html>";
		res.end(out);
	});
}).listen(3000, 'localhost');

client_require.listen(app);

Client/Server Alternation

If you want to have separate versions of particular files for the client and the server, you can do so by placing the module in a directory called client/ or server/, respectively.

Example:

server/
	app.js
client/
	app.js

This will create a module file at the root path app.js. client/app.js will be loaded on the client and server/app.js will be loaded on the server.

On the server-side, you must use the require method exported by the library to properly load server-side files.

API Methods

getScripts

Will callback with an array of script srcs to inject into the page, in order.

listen

Attaches a request event to the HTTP server to serve files which start with the provided web_root configuration.

require

This is useful on the server-side, as the standard require function is not able to be overloaded. This will make sure you load server/foo.js when there is no root foo.js available, which mimicks the client-side functionality.

Configuration

web_root

The root web path to load files from. Defaults to /js/.