Created
July 15, 2024 14:42
-
-
Save bobisme/490c2bd925c240c54b67a9ab8163db7e to your computer and use it in GitHub Desktop.
Set up a REPL at the end of a script with history and preview.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as path from "node:path"; | |
import * as repl from "node:repl"; | |
(async () => { | |
// MAIN EXECUTION/SETUP GOES HERE | |
const replServer = repl.start({ | |
prompt: ">> ", | |
useColors: true, | |
preview: true, | |
}); | |
const historyFile = path.join(process.env.HOME ?? "", ".node_repl_history"); | |
replServer.setupHistory(historyFile, (err) => { | |
if (err) console.warn("Failed to setup history:", err); | |
}); | |
// SET UP CONTEXT TO BE AVAILABLE IN THE REPL | |
// replServer.context.thing = thing; | |
})().catch((err) => { | |
throw err; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment