SHARE
TWEET

Untitled

a guest Nov 21st, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const bodyParser = require('body-parser');
  3. const path = require('path');
  4. const mongoose = require('mongoose');
  5. const chalk = require('chalk');
  6. require('dotenv/config');
  7.  
  8. const app = express();
  9.  
  10. // Middlewares
  11. app.use(bodyParser());
  12.  
  13. // Set EJS Template
  14. app.set('view engine', 'ejs');
  15.  
  16. // Static folder
  17. const static_dir = path.join(__dirname, 'public');
  18. app.use(express.static(static_dir));
  19.  
  20. // Routes
  21. app.use('/home', require('./routes/home.js').router);
  22. app.use('/message', require('./routes/message').router);
  23.  
  24. // Connect to Database
  25. mongoose.connect(
  26.     process.env.MONGOLAB_URI,
  27.     { useNewUrlParser: true },
  28.     { useUnifiedTopology: true },
  29.     { useMongoClient:true },
  30.     () => {
  31.         console.log(chalk.green('Connected to Database!'));
  32. });
  33.  
  34. const PORT = process.env.PORT || 5000;
  35. app.listen(PORT, () => console.log(chalk.green(`Server running on port: ${PORT}`)));
  36.  
  37. module.exports = {
  38.  
  39.     // Test instance
  40.     server: () => {
  41.         app.get('/test', (res, req) => {
  42.             res.send('test');
  43.         });
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top