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 🙏

© 2026 – Pkg Stats / Ryan Hefner

yuan-dev

v0.0.5

Published

Run into DEV mode according to DEV environment variable

Readme

See CHANGE LOG for notable changes.

Yuan-DEV

yuan-dev makes it easy to return something different for debug.

Quick Start

For example, normally we will start the http server listening to port 80, however, we may want it listening to port 8080 instead when debugging:

// index.js

const http = require('http');
const dev = require('yuan-dev');

const server = http.createServer((req, res) => {
	res.end('Hello Yuan DEV!');
});

var port = dev('LOCAL', 8080, 80);
server.listen(port);

By default, the port will be 80. While run with env DEV set, port 8080 will be used:

DEV=LOCAL node index

Define Values For More Dev Modes

Of course, We can also do it by the way more ordinary:

var port = dev('LOCAL') ? 8080 : 80;

Or, to accomplish more, we can define different values:

var port = dev({ LOCAL: 8080, FAT: 8088, UAT: 3000 }, 80);

The, we will get:

# port 8088
DEV=FAT node index

# port 3000
DEV=UAT node index

The DEV environment variable SHOULD be comma-delimited names, e.g.

DEV=FAT,INFO node index

About Returned Values

Although the values used in yuan-dev are generally simple scalars (number, string or boolean), they may also be anything including function object:

var fnGetPort = dev({
	LOCAL : () => 8080 },
	FAT   : () => 8088 },
	UAT   : () => 3000 }
}, () => 80 );

var port = fnGetPort();

Do Something On Dev Mode

And, if you want do something special on dev mode, dev.action() is helpful:

var port = dev({
	LOCAL: dev.action(() => {
		console.log('The server will listen to 8080.');
		return 8080;
	}
}, 80);

dev.action() will not do play outside of dev().

However, another method is offered:

//  Run immediately on DEV mode.
dev.run(() => {
	console.log('We are under DEV mode now.');
});

// Equals to,
if (dev()) {
	console.log('We ares under DEV mode now.');
}

// Of course, we can do something ONLY on special DEV mode.
dev.run('LOCAL', () => {
	console.log('We are under DEV mode (LOCAL) now.');
});

// In more complex cases, we can use functions similiar to logic control statements.
// if() ... elif()/elseif() ... else()
dev
	.if('LOCAL', () => {
		console.log('We are under DEV mode (LOCAL) now.');
	})
	.elseif('FAT', () => {
		console.log('We are under DEV mode (FAT) now.');
	})
	.else(() => {
		console.log('We ares NOT under DEV mode (LOCAL) or DEV mode (FAT) now.');
		console.log('ATTENTION: But maybe we are under some DEV mode other than LOCAL or FAT.');
	});

dev
	.if(() => {
		console.log('We are under DEV mode.');
	})
	.else(() => {
		console.log('We are NOT under any DEV mode.');
	})

Not everybody like this syntax sugar, but I think it is more elegant using dev.if().else() than the general if ... else ... control statement.

more

Run the next commands to install devDependencies and run mocha unit test:

npm install
npm test