Socket
Book a DemoInstallSign in
Socket

promisify-child-process

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promisify-child-process

seriously like the best async child process library

4.1.2
latest
Source
npmnpm
Version published
Maintainers
1
Created

What is promisify-child-process?

The promisify-child-process package is a utility that allows you to use Node.js child processes with promises, making it easier to work with asynchronous operations. It wraps the standard child process methods to return promises, enabling the use of async/await syntax for cleaner and more readable code.

What are promisify-child-process's main functionalities?

Promisified exec

This feature allows you to execute shell commands using the exec function and handle the result with promises. The code sample demonstrates how to run the 'ls' command and handle its output using async/await.

const { exec } = require('promisify-child-process');

async function runCommand() {
  try {
    const { stdout, stderr } = await exec('ls');
    console.log('Output:', stdout);
  } catch (error) {
    console.error('Error:', error);
  }
}

runCommand();

Promisified spawn

This feature allows you to spawn a new process using the spawn function and handle its lifecycle with promises. The code sample demonstrates how to spawn a process to list directory contents and handle its output and errors.

const { spawn } = require('promisify-child-process');

async function runSpawn() {
  const child = spawn('ls', ['-lh', '/usr']);

  child.stdout.on('data', (data) => {
    console.log(`stdout: ${data}`);
  });

  child.stderr.on('data', (data) => {
    console.error(`stderr: ${data}`);
  });

  try {
    await child;
    console.log('Process completed');
  } catch (error) {
    console.error('Error:', error);
  }
}

runSpawn();

Other packages similar to promisify-child-process

Keywords

child

FAQs

Package last updated on 10 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.