PageRenderTime 98ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/app/templates/server/app.js

https://gitlab.com/javajamesb08/generator-angular-fullstack
JavaScript | 37 lines | 22 code | 7 blank | 8 comment | 5 complexity | 6187cfb597578af096d5f6c54eaf6b15 MD5 | raw file
  1. /**
  2. * Main application file
  3. */
  4. 'use strict';
  5. // Set default node environment to development
  6. process.env.NODE_ENV = process.env.NODE_ENV || 'development';
  7. var express = require('express');<% if (filters.mongoose) { %>
  8. var mongoose = require('mongoose');<% } %>
  9. var config = require('./config/environment');
  10. <% if (filters.mongoose) { %>
  11. // Connect to database
  12. mongoose.connect(config.mongo.uri, config.mongo.options);
  13. // Populate DB with sample data
  14. if(config.seedDB) { require('./config/seed'); }
  15. <% } %>// Setup server
  16. var app = express();
  17. var server = require('http').createServer(app);<% if (filters.socketio) { %>
  18. var socketio = require('socket.io')(server, {
  19. serveClient: (config.env === 'production') ? false : true,
  20. path: '/socket.io-client'
  21. });
  22. require('./config/socketio')(socketio);<% } %>
  23. require('./config/express')(app);
  24. require('./routes')(app);
  25. // Start server
  26. server.listen(config.port, config.ip, function () {
  27. console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
  28. });
  29. // Expose app
  30. exports = module.exports = app;