So itโs possible, but you need serious hacking to make it work. Since this is not a node module and is written in a browser, as others have noted, it requires the DOM inside the node to execute it. Fortunately, we have a wonderful jsdom project that allows us to do just that. So let it tune.
cd into your node project (create it if it is not already)- clone jsrepl repo
git clone git://github.com/replit/jsrepl.git - cd in
jsrepl and initialize submodules git submodule update --init --recursive - still in the folder, run
npm install coffee-script and npm install uglify-js , dependencies that are not mentioned anywhere in the repo (ugh). - make sure java is installed and running
cake bake . After a lengthy process of compiling java files and such a command will complete, and jsrepl will be built and ready to go. - run
npm install jsdom , then we can start writing an example file
Here's a minimal example:
var jsdom = require('jsdom'), fs = require('fs'), jsrepl = fs.readFileSync('./jsrepl/repl.js', 'utf8'); jsdom.env({ html: "<script src='jsrepl.js' id='jsrepl-script'></script> ", src: [jsrepl], done: function(err, window){ if (err) return console.error(err); run_jsrepl.call(window); } }); function run_jsrepl(){ console.log(this.JSREPL) }
Here is the minimum amount of code needed to get jsrepl to its place of work. All we do here is jsdom requirement and its creation, reading in jsrepl source directly from the file. If you run this file using node filename , it will exit your jsrepl object, which can be used in the same way as in the browser :)
Jeff escalante
source share