Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //server.js
- const hapi = require('hapi');
- const server = new hapi.Server();
- const mongoose = require('mongoose');
- const mongoDbUri = 'mongodb://localhost:27017/hapi_db';
- //connect with mongoDB
- mongoose.connect(mongoDbUri, {
- useMongoClient: true
- });
- mongoose.connection.on('connected', () => {
- console.log(`app is connected to ${mongoDbUri}`);
- });
- mongoose.connection.on('error', err => {
- console.log('error while connecting to mongodb', err);
- });
- server.connection({
- host: 'localhost',
- port: '3000'
- });
- server.route({
- path: '/',
- method: 'GET',
- handler(req, reply) {
- reply('Welcome to HapiJs course!!');
- }
- });
- server.start(err => {
- if (err) {
- throw err;
- }
- console.log(`Server Running at PORT ${server.info.port}`);
- });
Add Comment
Please, Sign In to add comment