New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

system-commands

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

system-commands

Run system commands in Node.js

latest
Source
npmnpm
Version
1.1.7
Version published
Maintainers
1
Created
Source

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

Keywords

system-commands

FAQs

Package last updated on 09 Sep 2019

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