Advanced isomorphic asynchronous spawn function

Advanced isomorphic asynchronous spawn function

advanced-spawn-async .Advanced isomorphic asynchronous spawn function

advanced-spawn-async

Advanced isomorphic asynchronous spawn function

Requirements

  • Node.js ≥ 8.9.0

Usage

Basic Usage

Usage without custom spawn function (i.e. Use built-in child_process.spawn).

import spawn from 'advanced-spawn-async'

const {
  process, // ChildProcess
  onclose, // Promise<{ command, args, options, stdout, stderr, output, status, signal, process }>
  onexit // Promise<{ command, args, options, stdout, stderr, output, status, signal, process }>
} = spawn('node')

process.stdin.write('console.info("stdout")\n')
process.stdin.write('console.error("stderr")\n')
process.stdin.end('require("process").exit(0)\n')

onclose.then(({ stdout, stderr, output }) => {
  console.log('CLOSE', { stdout, stderr, output })
})

onexit.then(({ stdout, stderr, output }) => {
  console.log('EXIT', { stdout, stderr, output })
})

Sample Output:

EXIT {
  stdout: 'stdout\n',
  stderr: 'stderr\n',
  output: 'stdout\nstderr\n'
}
CLOSE {
  stdout: 'stdout\n',
  stderr: 'stderr\n',
  output: 'stdout\nstderr\n'
}

Custom Spawn Function

User provide custom spawn function.

import { core } from 'advanced-spawn-async'
import spawn from 'cross-spawn'

const { process, onclose, onexit } = core(spawn, 'node')

// The rest is like the above example

Provide Arguments and Options

import spawn from 'advanced-spawn-async'
const { onclose } = spawn('echo', ['hello'], { stdio: 'inherit', event: 'close' })
onclose.then(status => console.log({status}))

Non-Zero Status Code

When process returns non-zero code.

import spawn from 'advanced-spawn-async'
const { process, onclose } = spawn('node', [], { event: 'close' })
process.stdin.end('process.exit(123)\n')
onclose.catch(error => console.log(error.info))

Download Details:

Author: ksxnodemodules

Source Code: https://github.com/ksxnodemodules/advanced-spawn-async

node nodejs javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Node canvas is a Cairo backed Canvas implementation for NodeJS.

node-canvas is a Cairo-backed Canvas implementation for Node.js.

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Hire NodeJs Developer

Looking to build dynamic, extensively featured, and full-fledged web applications? **[Hire NodeJs Developer](https://hourlydeveloper.io/hire-dedicated-node-js-developer/ "Hire NodeJs Developer")** to create a real-time, faster, and scalable...

Decoding Nodejs

The main goal of this blog is to explain the “Architecture of Nodejs” and to know how the Nodejs works behind the scenes. Generally, most of the server-side languages, like PHP, ASP.NET, Ruby, and including Nodejs follows multi-threaded architecture. That means for each client-side request initiates a new thread or even a new process.

Node.js for Beginners - Learn Node.js from Scratch (Step by Step)

Node.js for Beginners - Learn Node.js from Scratch (Step by Step) - Learn the basics of Node.js. This Node.js tutorial will guide you step by step so that you will learn basics and theory of every part. Learn to use Node.js like a professional. You’ll learn: Basic Of Node, Modules, NPM In Node, Event, Email, Uploading File, Advance Of Node.