KeystoneJS error cannot install on openshift

144 views Asked by At

I am trying to run keystone for the first time using this init js:

var keystone = require('keystone');

var db_name = 'www';

if(process.env.OPENSHIFT_MONGODB_DB_PASSWORD){
  connection_string = process.env.OPENSHIFT_MONGODB_DB_USERNAME + ":" +
  process.env.OPENSHIFT_MONGODB_DB_PASSWORD + "@" +
  process.env.OPENSHIFT_MONGODB_DB_HOST + ':' +
  process.env.OPENSHIFT_MONGODB_DB_PORT + '/' +
  process.env.OPENSHIFT_APP_NAME;
}

var mongoDbConnectionString =  process.env.OPENSHIFT_MONGODB_DB_URL ||
 'mongodb://admin:[email protected]:27017/www';

var keystone = require('keystone');
keystone.init({

'name': 'tester',

'favicon': 'public/favicon.ico',

'views': 'templates/views',
'view engine': 'jade',

'auto update': true,
'mongo': connection_string,

'session': true,
'auth': true,
'user model': 'User',
'cookie secret': '(your secret here)'

});

require('./models');

keystone.set('routes', require('./routes'));

keystone.start();

I get this error when I run the file:

module.js:338
throw err;
^
Error: Cannot find module './models'
at Function.Module._resolveFilename (module.js:336:15)

at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (d:\Source\openshift-www\www\web.js:48:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

Process finished with exit code 1

I can log in to my mongodb fine using robo mongo and the credentials above, can anyone please tell how I can get Keystone up and running?

1

There are 1 answers

0
JME On BEST ANSWER

Assuming you have all your model in the ./models folder you can use require('./models') but only if you have a ./models/index.js requiring all the models.

An alternative is to use Keystone's .import() method. Below is an example:

keystone.import('models');