node.js - Loading node-orm2 through a promise, causes CWD and module not found -
I have a function that loads my node-ORM model:
function (Server, Connectionstring) {server.use (orm.express (connectionString, {define: function (db, model, next) {loadIdeaDomain (db) next ()}})) Return it}
There is another piece of middleware (passport) that needs to be run after loading node-ORM models ... but the Enic nature is making me crazy. Can I convert to one of the above mentioned promises or Before moving forward I can wait to be executed?
Let's update the loading
var loadIdeaDomain = function (db) {var ideaDomainPath = './idea-domain/idea-domain.js' Console.log ('Loading' '+ DimaManPath) var qLoad = Q.nbind (db.load, db) return qLoad (ideaDomainPath). Then (function () {console .log ('THEN') defined Models = db.moles _.ech (_. Key (db.models), function (modelname) {macproomijes (db model [modelname], modelname}}) Returns db.models}, function (e) {console.log ('ERR') console.log (e)})}
It seems that this will work, except me Error getting:
{[Error: module 'C: \ users \ todd \ document \ web \ nodeTest \ trq \ node_modules \ q / .idea-domain / idea-domain.js '] Code can not be found:' MODULE_NOT_FOUND '}
So it seems E-YM library module Utilities.js and this amazing work:
export.getRealPath = function (path_str, stack_index) {var path = requirement ("path "); // For now, load here (only when needed) var cwd = process.cwd (); Var err = new error (); Var tmp = err.stack.split (/ \ r? \ N /) [Typeof stack_index! == "undefined"? Stack_index: 3], m; if ((m = tmp.match (/ ^ \ s * at \ s + (. +): \ D +: \ d + $ /))! == faucet) {cwd = path.dirname (m [1]); } And if ((m = tmp.match (/ ^ \ s * at \ s + module .exports \ s + \ ((+.?) \) /))! == ft {cwd = path.dirname ( Meter [1]);} and if ((m = tmp.match (/ ^ \ s * at \ s +. + \ S + \ ((. +): \ D +: \ d + \) $ /) ) == faucet) {cwd = path.dirname (m [1]);} If (path_str [0]! == path.sep) {path_str = cwd + "/" + path_str;} If (path_str.substr () -1) === path.sep} {path_str + = "index";} return path_stroll;};
this is a problem which is a problem
< Code> path_str = cwd + "/" + path_str;
well, I did this one I decided to override the load method in place ORM.js for the location in this form Defined:
var loadViaFullPath = function {var files = _.flatten (Array.prototype.slice.apply (arguments)); var cb = function () {}; if (File type [files.length - 1] == "function") {cb = files.pop ();} var loadNext = function () {if (files.length === 0) {return cb (); } Var file = files.shift (); {// Notification utilities need to return the use (file) (this, function (mistake) {if (return) return cb (err); return loadNext ();}); } Grip (east) {return CB (east); }} Rebellion (this); Return loadNext (); }
then
var loadIdeaDomain = function (db) {var ideaDomainPath = __dirname + '/idea-domain/idea-domain.js' console log ('Loading' '+ DymanPath) db.load2 = loadViaFullPath var qLoad = Q.nbind (db.load2, db) Return qLoad (ThinkDimensionPath) Then (function () {_.each (_ keys (db.models), Function (modelName) {makeQPromises (db.models [modelName], modelName)} Returns db.models}}}
And I call it like this:
server.use (orm.express (connectionString, {define: function (db, models, next) {loadIdeaDomain (db)
Comments
Post a Comment