Created
March 19, 2016 07:01
-
-
Save tjwebb/89ba12f8c9954273a52f to your computer and use it in GitHub Desktop.
Create a Node REPL with History
This file contains hidden or 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
const repl = require(‘repl’) | |
const server = repl.start({ /* your config options */ }) | |
// synchronous methods are fine, here. you don't want to run a REPL on any middleware that | |
// handles user requests, anyway. | |
fs.statSync('.node_repl_history') | |
// load command history from a file called .node_repl history in the current directory | |
fs.readFileSync('.node_repl_history') | |
.split(‘\n’) | |
.reverse() | |
.filter(line => line.trim()) | |
.map(line => server.history.push(line)) |
This file contains hidden or 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
// write commands used in current session to file | |
fs.appendFileSync(this.node_repl_history, this.server.lines.join('\n')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment