运行如下代码的节点输出为:
all Loaded
dbModule undefined
mongoose loaded
我无法在 appMod2 中获得对 dbMod2 的引用。我应该尝试什么?
//server.js
var requirejs = require( 'requirejs');
process.on( 'uncaughtException', function(error) {
console.log( 'Exception ' + error.stack);
process.exit( 1);
});
requirejs.config({
baseUrl: '.',
nodeRequire: require
});
requirejs(['./appMod2'], function() {
console.log( "all Loaded");
})
// appMod2.js
require(['./dbmod2'], function( dbmodule) {
console.log( "dbModule " + dbmodule);
});
// dbmod2.js
require(['mongoose'], function( mongoose) {
Schema = mongoose.Schema;
console.log( "mongoose loaded");
});