repl2http
v1.0.13
Published
A Node.js REPL server that runs over HTTP from any directory
Downloads
398
Maintainers
Readme
REPL2HTTP
A Node.js REPL server that runs over HTTP, allowing you to execute JavaScript code in your current directory context from any client.
Features
- 🚀 Run JavaScript code in your project's context via HTTP
- 🔄 Automatically resolves
require()
statements relative to your current directory - 📦 Works with local modules and installed npm packages
- 🔒 Captures and returns console output
- 🛠️ Simple HTTP API for integration with any client
Important Notes
Working Directory
REPL2HTTP uses the directory from which it was started as the current working directory. All relative paths in require()
statements will be resolved relative to this directory.
For example, if you start the server from your project root:
cd /path/to/my/project
npx repl2http
Then require('./lib/myModule')
will look for the module at /path/to/my/project/lib/myModule.js
.
If you start it from a subdirectory:
cd /path/to/my/project/src
npx repl2http
Then require('./utils')
will look for the module at /path/to/my/project/src/utils.js
.
Installation
# Install globally
npm install -g repl2http
# Or run directly with npx
npx repl2http
Usage
Starting the Server
# Start with default settings (port 3000)
npx repl2http
# Specify a custom port
npx repl2http --port 8080
# Enable debug logging
npx repl2http --debug
# Show detailed environment information
npx repl2http --verbose
Command Line Options
-p, --port PORT
- Set the port number (default: 3000)-d, --debug
- Enable debug logging-v, --verbose
- Show detailed environment information-h, --help
- Display help information
HTTP API
Server Info
GET /
Returns information about the server, including:
- Server status
- API usage information
- Node.js version
- Current working directory
Execute Code
POST /repl
Content-Type: application/json
{
"code": "const result = 2 + 2; console.log('Calculation result:', result); result;"
}
Returns:
{
"result": 4,
"output": ["[log] Calculation result: 4"],
"cwd": "/your/current/directory"
}
Examples
Basic Arithmetic
{ "code": "2 + 2" }
Working with Files
{ "code": "const fs = require('fs'); fs.readdirSync('.')" }
Requiring Local Modules
{ "code": "const myModule = require('./lib/myModule'); myModule.doSomething()" }
Async/Await Support
{ "code": "async function test() { return 'async result'; }; return await test()" }
Security Considerations
⚠️ Important: REPL2HTTP executes arbitrary JavaScript code in your environment. Only use it in trusted environments (like development) and never expose it to the public internet.
License
MIT