https://github.com/darky/node-remote-repl
Node.js remote code execution via inspect protocol for REPL driven development
https://github.com/darky/node-remote-repl
execution inspect node nodejs remote repl
Last synced: 10 months ago
JSON representation
Node.js remote code execution via inspect protocol for REPL driven development
- Host: GitHub
- URL: https://github.com/darky/node-remote-repl
- Owner: darky
- Created: 2020-04-05T14:13:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T08:40:20.000Z (over 1 year ago)
- Last Synced: 2025-04-25T21:52:20.196Z (10 months ago)
- Topics: execution, inspect, node, nodejs, remote, repl
- Language: TypeScript
- Homepage:
- Size: 179 KB
- Stars: 17
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-remote-repl
Execute code remotelly via Node.js inspect protocol like Clojure nREPL. Primary usage for REPL driven development.
### Install
```
npm install -g node-remote-repl
```
### Usage
You can always get help of cli:
```
node-remote-repl --help
```
Output:
```
Usage: node-remote-repl [options]
Options:
-V, --version output the version number
-h, --host host of inspect protocol (default: "localhost")
-p, --port port of inspect protocol (default: 9229)
-h, --help display help for command
```
Ok, it's very easy, create for example `repl.js` and play with it
```
node-remote-repl --host some-host --port 9229 repl.js
```
Also TypeScript supported too
```
node-remote-repl --host some-host --port 9229 repl.ts
```
If you want to use fast TypeScript compiler
```
USE_SWC=1 node-remote-repl --host some-host --port 9229 repl.ts
```
*For TypeScript support should be installed **typescript** or **@swc/core** (when USE_SWC=1) in your `devDependencies`*
### Some use cases
#### log to stdout of your remote process
```js
console.log(/* some stuff */);
```
#### expose something from remote process
```js
exports.$repl = async () => {
return 1 + 1;
};
```
#### expose some json from remote process
```js
exports.$replJson = async () => {
return {obj: true};
};
```
#### use power of require
```js
const util = require('util');
const module = require('./some-module');
exports.$repl = async () => {
return util.inspect(module.method(), {colors: true});
};
```
#### typescript support out of the box
```ts
exports.$repl = async () => {
const n: number = 1;
return n;
};
```
#### you can replace implementation on remote side
```js
const Module = require('./some-module');
Module.prototype.method = () => {
// replace implementation on the fly
};
```
### Integration with IDE
Because it simple command line util, you can easy integrate it with your IDE.
For example let's do it with Visual Studio Code and Code Runner extension:
* install Code Runner extension to Visual Studio Code
* configure Code Runner to run `node-remote-repl` in `repl.js`:
```json
{
"code-runner.executorMapByGlob": {
"repl.js": "node-remote-repl --host some-host --port 9229"
}
}
```
* profit, now you can fastly run repl via Visual Studio Code
* I hope, some similar stuff exists on all popular IDE
### Related
* [repl-ns](https://github.com/darky/repl-ns) -
Namespace for REPL driven development for TypeScript/JavaScript, inspired by Clojure namespaces