https://github.com/gera2ld/clean-run
Run a Node.js script in a clean environment
https://github.com/gera2ld/clean-run
Last synced: about 2 months ago
JSON representation
Run a Node.js script in a clean environment
- Host: GitHub
- URL: https://github.com/gera2ld/clean-run
- Owner: gera2ld
- Created: 2021-05-25T07:19:41.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-27T06:29:54.000Z (about 5 years ago)
- Last Synced: 2025-01-15T05:52:54.496Z (over 1 year ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# clean-run
[](https://npm.im/clean-run)


Run a Node.js script in a clean environment without caring about the dependencies. This is a `deno run` alternative that works for Node.js.
Requires Node.js >= 14.14.0.
## Motivation
When running a CI script, it is likely that we don't need all dependencies defined in a `package.json`. It might take relatively long time and high bandwidth to install all of them, especially when there are Electron and its friends. In areas with low bandwidth or poor network connections this may be a bigger problem as installation may fail and we have to care about packages that we don't even need.
If you are familiar with Deno, you will miss the feature to run a script with all the dependencies from remote. With `clean-run` you can easily run a script like that in Node.js.
If you are tired of writing obscure Bash scripts, you can write a Node.js script and let `clean-run` to deal with the dependencies.
## How does this work?
`clean-run` scans the entry script file to see what packages it really depends on and only install those needed. We don't have to set mirrors and wait for large packages that are not even required.
## Usage
```
Usage:
$ clean-run [options] [other arguments ...]
path to the main script, set to - if piped from stdin
Options:
-s suppress npm logs
```
You will need to install this one dependency first.
```bash
$ npm install clean-run
$ clean-run my-script.js
```
Or you can use npx to get a one-liner:
```bash
$ npx clean-run -s my-script.js
```
You can even run a remote script directly (try it by yourself 👇🏻):
```bash
$ curl -fsSL https://raw.githubusercontent.com/gera2ld/clean-run/master/demos/cowsay.js | npx clean-run -s -
```