Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /**
  2. * @package [db] - Application db connection & schema loading
  3. * @author [anikett] smartData Inc
  4. */
  5.  
  6. 'use strict';
  7.  
  8. /* DB */
  9. var mongoose = require('mongoose');
  10. mongoose.Promise = Promise;
  11.  
  12. require('../api/models/Component');
  13. require('../api/models/User');
  14. require('../api/models/Category');
  15.  
  16. /* database uri */
  17. var uri = 'mongodb://' + process.env.DB_HOST + ':' + process.env.DB_PORT + '/' + process.env.DB_NAME;
  18.  
  19. var options = {
  20. user: process.env.DB_USERNAME,
  21. pass: process.env.DB_PASSWORD,
  22. server: {
  23. socketOptions: {
  24. keepAlive: 1,
  25. connectTimeoutMS: 30000
  26. }
  27. },
  28. replset: {
  29. socketOptions: {
  30. keepAlive: 1,
  31. connectTimeoutMS: 30000
  32. }
  33. }
  34. }
  35.  
  36. mongoose.connect(uri, options);
  37.  
  38. var db = mongoose.connection;
  39. db.on('error', console.error.bind(console, 'connection error:'));
  40. db.once('open', function(callback) {
  41. console.log('Database connection successful!');
  42. });
  43. /* end DB */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement