×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Mega Tron
Added: Sep 11, 2016 8:17 PM
Views: 6
Tags: hapi server
  1. 'use strict';
  2.  
  3. const Hapi = require('hapi');
  4.  
  5. // Create a server with a host and port
  6. const server = new Hapi.Server();
  7. server.connection({
  8.     host: 'localhost',
  9.     port: 8000
  10. });
  11.  
  12. // Add the route
  13. server.route({
  14.     method: 'GET',
  15.     path:'/hello',
  16.     handler: function (request, reply) {
  17.  
  18.         return reply('hello world');
  19.     }
  20. });
  21. // Start the server
  22. server.start((err) => {
  23.  
  24.     if (err) {
  25.         throw err;
  26.     }
  27.     console.log('Server running at:', server.info.uri);
  28. });