system-commands
Run system commands in Node.js
Last updated a year ago by kenmueller .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install system-commands 
SYNC missed versions from official npm registry.

System commands for JavaScript

Run system commands in Node.js

Installation

npm i system-commands

JavaScript

const system = require('system-commands')

TypeScript

import system = require('system-commands')

Tutorial

Run any command using system(COMMAND). The output is passed into the .then block, and the error (if any) is passed into the .catch block.

/**
 * Runs a system command
 * 
 * Parameter `command` - The command you want to run, like `ls` or `mkdir new_directory`
 * 
 * Returns a `Promise` containing the output of the command.
 * If the command failed, the error is passed into the `.catch` block.
 */
function system(command: string): Promise<string>

Run the command ls:

// async/await

console.log(await system('ls'))

// Handling errors

system('ls').then(output => {
	// Log the output
	console.log(output)
}).catch(error => {
	// An error occurred! Log the error
	console.error(error)
})

// Or for a more concise statement...

system('ls').then(console.log).catch(console.error)

// Output:

/*
 * README.md
 * lib
 * node_modules
 * package-lock.json
 * package.json
 * src
 * tests
 * tsconfig.json
 * tslint.json
 * types
 */

Make a new directory:

system('mkdir new_directory').then(() => {
	// Directory was created
	console.log('Successfully created new_directory')
}).catch(error => {
	// Oh no! An error occurred
	console.error(error)
})

// Output:
// Successfully created directory

Current Tags

  • 1.1.7                                ...           latest (a year ago)

18 Versions

  • 1.1.7                                ...           a year ago
  • 1.1.6                                ...           a year ago
  • 1.1.5                                ...           a year ago
  • 1.1.4                                ...           a year ago
  • 1.1.3                                ...           a year ago
  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.9                                ...           a year ago
  • 1.0.8                                ...           a year ago
  • 1.0.7                                ...           a year ago
  • 1.0.6                                ...           a year ago
  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 18
Dependencies (0)
None
Dev Dependencies (5)

Copyright 2014 - 2016 © taobao.org |