Socket
Socket
Sign inDemoInstall

shelljs

Package Overview
Dependencies
Maintainers
3
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shelljs

Portable Unix shell commands for Node.js


Version published
Weekly downloads
1.5M
decreased by-80.21%
Maintainers
3
Weekly downloads
 
Created

What is shelljs?

ShellJS is a portable (Windows/Linux/OS X) implementation of Unix shell commands on top of the Node.js API. It provides the ability to script shell commands within JavaScript files and is used for tasks such as file manipulation, program execution, and script automation.

What are shelljs's main functionalities?

File Operations

ShellJS can perform file operations such as copying, removing, and moving files or directories.

const shell = require('shelljs');
shell.cp('-R', 'source_folder', 'destination_folder');
shell.rm('-rf', 'folder_to_delete');
shell.mv('old_file.txt', 'new_file.txt');

Executing Shell Commands

It can execute any shell command and capture its output.

const shell = require('shelljs');
let output = shell.exec('echo hello world', {silent:true}).stdout;
console.log(output);

Searching and Modifying Files

ShellJS can search for files that match a pattern and perform text replacement within files.

const shell = require('shelljs');
let files = shell.find('.').filter(file => file.match(/\.js$/));
shell.sed('-i', 'original_text', 'new_text', 'file.js');

Environment Variables

It allows manipulation of environment variables within a script.

const shell = require('shelljs');
shell.env['VAR_NAME'] = 'value';
console.log(shell.env['VAR_NAME']);

Directory Navigation

ShellJS can change the current working directory and get the present working directory.

const shell = require('shelljs');
shell.cd('path/to/directory');
console.log(shell.pwd().stdout);

Other packages similar to shelljs

Keywords

FAQs

Package last updated on 25 Apr 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc