nodejs / nodejs/node

Add Promise-based versions for some functions in child_process

Offen
#49,904 19 Kommentare 32 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature request never-stale
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

What is the problem this feature will solve?

It would be nice if child_process functionality, such as exec and execFile, had Promised based versions by default. Currently it does not, see https://nodejs.org/api/child_process.html

Note that only child_process functions that can be async/await should be considered. This does not include things such as fork or spawn.

What is the feature you are proposing to solve the problem?

A new child_process/promises import path that can be used similar to how fs promises are used:

// Using ESM Module syntax:
import { exec } from 'child_process/promises';

try {
  const { stdout } = await exec(
    'sysctl -n net.ipv4.ip_local_port_range'
  );
  console.log('successfully executed the child process command');
} catch (error) {
  console.error('there was an error:', error.message);
}

The ask is basically that child_process/promises could just return a variant such as const exec = util.promisify(process.exec); as a convenience.

What alternatives have you considered?

I am already using const exec = util.promisify(process.exec); but that is not as nice. And this new proposal follows along what is happening in other Node.js APIs.

(The original ask in https://github.com/nodejs/node/issues/38823 was perceived as asking for the entire module and all APIs to be async/await. This issue here narrows it down to only focus on the functions that can be.)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Vergleich des vorgeschlagenen Einstiegspunkts child_process/promises mit der bestehenden fs promises API und dem in Issue #38823 diskutierten Umfang. Bestimme, welche asynchron unterstützenden child_process-Funktionen bereitgestellt werden sollten, und überprüfe anschließend, dass API-Form, Dokumentation und Tests diese Funktionen abdecken, ohne fork oder spawn einzuschließen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, node.js
Bereich
api, backend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.