Skip to content

Instantly share code, notes, and snippets.

@tjwebb
Created March 19, 2016 07:01
Show Gist options
  • Save tjwebb/89ba12f8c9954273a52f to your computer and use it in GitHub Desktop.
Save tjwebb/89ba12f8c9954273a52f to your computer and use it in GitHub Desktop.
Create a Node REPL with History
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))
// 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