Guest User

Untitled

a guest
Feb 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. //server.js
  2. const hapi = require('hapi');
  3. const server = new hapi.Server();
  4. const mongoose = require('mongoose');
  5. const mongoDbUri = 'mongodb://localhost:27017/hapi_db';
  6.  
  7. //connect with mongoDB
  8. mongoose.connect(mongoDbUri, {
  9. useMongoClient: true
  10. });
  11. mongoose.connection.on('connected', () => {
  12. console.log(`app is connected to ${mongoDbUri}`);
  13. });
  14. mongoose.connection.on('error', err => {
  15. console.log('error while connecting to mongodb', err);
  16. });
  17. server.connection({
  18. host: 'localhost',
  19. port: '3000'
  20. });
  21. server.route({
  22. path: '/',
  23. method: 'GET',
  24. handler(req, reply) {
  25. reply('Welcome to HapiJs course!!');
  26. }
  27. });
  28. server.start(err => {
  29. if (err) {
  30. throw err;
  31. }
  32. console.log(`Server Running at PORT ${server.info.port}`);
  33. });
Add Comment
Please, Sign In to add comment