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

lazy-command.js

v1.0.1

Published

Rust-like Command wrapper over node.js child_process

Downloads

3

Readme

lazy-command.js

Build Status Coverage Status

Rust-like Command wrapper over node.js child_process

It provides simple & unified builder for Node.js child_process

Overview

Defaults

  • Inherits parent's environment.
  • Inherits parent's current directory.

Execution methods

  • spawn - Equal to child_process.spawn or child_process.spawnSync.
  • exec - Equal to child_process.exec or child_process.execSync.
  • execFile - Equal to child_process.execFile or child_process.execFileSync.
  • output - Equal to child_process.spawnSync but returns only status, stdout and stderr.
  • status - Equal to child_process.execSync but returns only status.

Sync vs Async

By default Command executes asynchronously.

In order to configure command for synchronous execution you need to call method sync

For example to perform exec synchronously:

const status = require('lazy-command.js')('git -status').sync().exec()

For asynchronous version you need to omit sync.

const status = require('lazy-command.js')('git -status').exec()

Async callback

Setting of callback is optional but method callback can be used to provide it.

The signature of callback is the same as for any corresponding child_process functions.

For example:

const cb = (err, stdout, stderr) => {
    console.log("Err=%s | stdout=%s | stderr=%s", err, stdout, stderr);
};
const status = require('lazy-command.js')('git -status').callback(cb).exec()

Examples

Collect all output of command

const Command = require('lazy-command.js');

const result = Command("git -status").encoding('utf-8').output();

console.log("status=% | stdout=%s | stderr=%s",
            result.status, result.stdout, result.stderr);

Just get status code

const Command = require('lazy-command.js');

const result = Command("git -status").stdio_ignore().status();;

console.log("Status=%s", result);

Let's make lot of configuration

const Command = require('lazy-command.js');

const result = Command("git").stdio_ignore()
                             .arg("-status")
                             .current_dir("lib/");
                             .timeout(1000)
                             .status();;

console.log("Status=%s", result);