There is still nothing built-in to provide the exact functionality you describe. However, an alternative to using require it to use the .load command within the REPL, like such:

.load foo.js

It loads the file in line by line just as if you had typed it in the REPL. Unlike require this pollutes the REPL history with the commands you loaded. However, it has the advantage of being repeatable because it is not cached like require.

Which is better for you will depend on your use case.


Edit: It has limited applicability because it does not work in strict mode, but three years later I have learned that if your script does not have 'use strict', you can use eval to load your script without polluting the REPL history:

var fs = require('fs');
eval(fs.readFileSync('foo.js').toString())
Answer from vossad01 on Stack Overflow
๐ŸŒ
Node.js
nodejs.org โ€บ en โ€บ learn โ€บ command-line โ€บ how-to-use-the-nodejs-repl
Node.js โ€” How to use the Node.js REPL
Node.js comes with a built-in REPL (Read-Eval-Print Loop) environment that allows you to execute JavaScript code interactively.
๐ŸŒ
Node.js
nodejs.org โ€บ api โ€บ repl.html
REPL | Node.js v25.2.1 Documentation
NODE_REPL_MODE: May be either 'sloppy' or 'strict'. Default: 'sloppy', which will allow non-strict mode code to be run. By default, the Node.js REPL will persist history between node REPL sessions by saving inputs to a .node_repl_history file located in the user's home directory.
Discussions

How do I load my script into the node.js REPL?
I have a script foo.js that contains some functions I want to play with in the REPL. Is there a way to have node execute my script and then jump into a REPL with all the declared globals, like I can More on stackoverflow.com
๐ŸŒ stackoverflow.com
Use of REPL in node js
What is the use of REPL in nodejs? What are the use-cases/scenario for using REPL? When should I use the REPL node module in nodejs? I have understood the API Doc, how to include REPL module and h... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to use repl to create a command-line shell for your Express project
๐ŸŒ r/node
1
9
December 15, 2021
Anybody who uses Replit instead of VScode for JavaScript? What are your opinions on it?
Replit is for quick and small projects to easily share. Learning VSCode is more important. Itโ€™s the most popular editor and works for any size project. You can still share code with GitHub or extensions. More on reddit.com
๐ŸŒ r/learnjavascript
11
10
July 11, 2023
๐ŸŒ
egghead.io
egghead.io โ€บ lessons โ€บ node-js-use-the-node-js-repl-shell
Use the Node.js REPL shell | egghead.io
In this lesson, you will learn how to use the interactive Node.js REPL (Read - Evaluate - Print - Loop) shell. The REPL shell allows you to enter javascript directly into a shell prompt and have the results evaluated by the node.js engine ...
Published ย  April 19, 2015
๐ŸŒ
Replit
replit.com โ€บ languages โ€บ nodejs
Node.js Online Compiler & Interpreter - Replit
Write and run Node.js code using our Node.js online compiler & interpreter. You can build, share, and host applications right from your browser!
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ nodejs โ€บ node-js-repl
Node js REPL | Scaler Topics
May 4, 2023 - REPL is an abbreviation for Read Evaluate Print Loop, which is a programming language environment (essentially a console window) that accepts a single expression as user input, executes it, and returns the result to the console after execution.
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ creating a custom repl for node.js
Creating a custom REPL for Node.js - LogRocket Blog
June 4, 2024 - REPL takes a user input, executes it, and returns an output. Learn how to use the Node.js inbuilt REPL environment or create a custom REPL.
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ nodejs โ€บ repl
GitHub - nodejs/repl: REPL rewrite for Node.js โœจ๐Ÿข๐Ÿš€โœจ
REPL rewrite for Node.js โœจ๐Ÿข๐Ÿš€โœจ. Contribute to nodejs/repl development by creating an account on GitHub.
Starred by 181 users
Forked by 24 users
Languages ย  JavaScript
๐ŸŒ
Codefinity
codefinity.com โ€บ courses โ€บ v2 โ€บ 3f76a477-4ae9-4a75-b782-1390d6f597ef โ€บ c294d959-7c84-44f0-acef-acfcc91b2420 โ€บ 8713cda3-007d-47f0-922e-8445bd48ad2a
Learn Using the Node.js REPL | Running Code and Working with the Node Environment
The Node.js REPL is a powerful tool that lets you run JavaScript code interactively, directly from your terminal. REPL stands for Read-Eval-Print Loop, and it provides an environment where you can quickly test snippets of code, experiment with ...
๐ŸŒ
TutorialsTeacher
tutorialsteacher.com โ€บ nodejs โ€บ nodejs-console-repl
Node.js Console/REPL
Node.js comes with virtual environment called REPL (aka Node shell). REPL stands for Read-Eval-Print-Loop. It is quick and easy way to test simple Node.js/JavaScript code.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-use-the-node-js-repl
How To Use the Node.js REPL | DigitalOcean
March 18, 2022 - The Node.js Read-Eval-Print-Loop (REPL) is an interactive shell that processes Node.js expressions. The shell reads JavaScript code the user enters, evaluateโ€ฆ
๐ŸŒ
Node.js
nodejs.org โ€บ download โ€บ release โ€บ v0.8.4 โ€บ docs โ€บ api โ€บ repl.html
REPL Node.js v0.8.4 Manual & Documentation
A Read-Eval-Print-Loop (REPL) is available both as a standalone program and easily includable in other programs. The REPL provides a way to interactively run JavaScript and see the results. It can be used for debugging, testing, or just trying things out. By executing node without any arguments ...
๐ŸŒ
The Valley of Code
thevalleyofcode.com โ€บ node-repl
How to use the Node.js REPL
REPL stands for Read-Evaluate-Print-Loop, and it's a great way to explore the Node features in a quick way
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ nodejs โ€บ nodejs_repl_terminal.htm
Node.js - REPL Terminal
The Node.js provides a REPL terminal, that allows to execute the JavaScript code interactively. It is an essential tool for testing, debugging and experimenting with JavaScript and Node.js features. The REPL is used to check the JavaScript functionality without setting up an entire development envir
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ node.js โ€บ node-js-repl-read-eval-print-loop
NodeJS REPL (READ, EVAL, PRINT, LOOP) - GeeksforGeeks
August 19, 2025 - The REPL is forgiving of errors and will display helpful error messages without crashing the entire session. This makes it a safe environment for testing. ... NodeJS REPL provides several built-in commands (REPL commands always start with a dot .).
๐ŸŒ
OneCompiler
onecompiler.com โ€บ nodejs
NodeJS Online Compiler
OneCompiler's NodeJS online editor helps you to write, compile, debug and run NodeJS code online
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ node.js
What is REPL in Node.js? How To Use & Explanation with an Example?
June 2, 2023 - REPL is a command-line tool that takes the input from the user and gives the desired output with the series of events undergoing between the two actions, one being the input and the other being output.
๐ŸŒ
W3Schools
w3schools.com โ€บ nodejs โ€บ nodejs_command_line.asp
Node.js Command Line Usage
The Node.js REPL (Read-Eval-Print Loop) is an interactive shell for executing JavaScript code.
Top answer
1 of 1
6

What are the use-cases/scenario for using REPL?

I've often seen it (or Chrome's console which is a JavaScript REPL as well) used in tech talks as a quick way to demonstrate what different expressions evaluate to. Let's image you're holding a talk about Equality in JavaScript and want to show that NaN strangely is not equal to itself.

You could demonstrate that by:

  • running node without arguments in your terminal (this starts the REPL)
  • entering NaN == NaN and pressing Enter (the REPL will evaluate the expression)
  • pretending to be surprised that the output is false

When should I use the REPL node module in nodejs?

When you want to implement a Node.js REPL as part of your application, for example by exposing it through a "remote terminal" in a web browser (not recommending that because of security reasons).

Examples

Replicating the REPL that is shown by calling node

const repl = require('repl')
const server = repl.start()

Using the REPLServer's stream API

fs-repl.js file:

const repl = require('repl')
const fs = require('fs')
const { Readable } = require('stream')

const input = new fs.createReadStream('./input.js')

const server = repl.start({
  input,
  output: process.stdout
})

input.js file:

40 + 2
NaN
["hello", "world"].join(" ")

You can now run node fs-repl and you will get the following output:

> 40 + 2
42
> NaN
NaN
> ["hello", "world"].join(" ")
'hello world'

This output can obviously be passed into a Writable stream other than process.stdout by changing the output option.