Skip to content

Instantly share code, notes, and snippets.

@paulserraino
Created June 29, 2015 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulserraino/c74f8108bb60e182af2c to your computer and use it in GitHub Desktop.
Save paulserraino/c74f8108bb60e182af2c to your computer and use it in GitHub Desktop.
sample custom node repl
var repl = require('repl');
var path = require('path');
var r = repl.start();
require('repl.history')(r, path.join(process.env.HOME, '.node_history');
var caterDir = '../cater-api-server' || process.argv[2];
r.context.models = require(path.join(caterDir, 'models');
r.context.db = require(path.join(caterDir, 'db');
r.context.utils = require(path.join(caterDir, 'utils');
r.context.config = require(path.join(caterDir, 'config');
/**
* raw sql query helper
* @param {String} query
*/
r.context.sql = function (query) {
r.context.db.query(query, function (error, results) {
if (error) return console.log(error);
// set results to the context variable 'results'
return r.context.results = results;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment