Created
June 29, 2015 19:34
-
-
Save paulserraino/c74f8108bb60e182af2c to your computer and use it in GitHub Desktop.
sample custom node repl
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
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