@seung_h/node-sh
v1.2.1
Published
Portable implementations and executions of bash commands for node.js
Downloads
2
Maintainers
Readme
Node-sh is a bash command implementation and os shell command execution for node.js that runs on mac os, linux and windows. It makes you easier to execute your os shell commands. implement bash commands and functionalize it.
🕹 Install
$ yarn add node-sh
$ npm install node-sh
🔥 Features
- TypeScript based, zero dependencies. 📦
- Simple command execution with user environment.
- 23 bash commands implemented.
- Each command supports type-based JavaScript API and pipe commands.
- Provides details about exceptions in user command with rendered code.
📌 Import
If the $
namespace conflicts, you can use named import rather than global import.
import 'node-sh' // $.commands
import bash from 'node-sh' // bash.commands
📝 Commands
Designed to be easy to use, node-sh uses only one interface. it can execute commands and implementations.
🔐 Execute
const exec = $ `ls -al | grep 'node-sh'`
Caution: This function uses the child process module to execute commands directly.
Environments
$.env: {
verbose : boolean = false
prefix : string = ''
shell : string | boolean = true
max_buffer : number = 200 * 1024 * 1024
} // structures
$.env.shell = $.which `git`
💡 Implement
Node-sh has implemented syntax and options, etc. similar to bash
based on linux man page to improve the user-experience.
🔗 UnixExtension
Each function (except void functions) returns stdout to UnixExtension
class that can use JavaScript API according to the type of stdout or pipe functions such as grep, sort, uniq, etc.
📖 Check the module has a default export.
import 'node-sh'
const output = $.cat `src/test.ts`.includes('export default')
📖 Get only directories.
import 'node-sh'
// Use JavaScript API
const api = $.ls `-al`.filter(data => data.startsWith('d'))
// Use UnixExtension
const extension = $.ls `-al`.grep `^d`
🛠 Exceptions
Node-sh provides detail of the exceptions that occurred in user commands or internal and suggests solutions for them.
Note: It is only used for errors handled within the module and cannot be used externally.
📋 License
Distributed under the MIT License. See LICENSE
for more information.