UNPKG

lesson04

Version:

first npm package try

36 lines (31 loc) 648 B
const Hapi = require('hapi') // Create a server with a host and port const server = new Hapi.Server() server.connection({ host: 'localhost', port: 3000 }) function sayhi(name) { return 'Hello ' + name + '! :-D' } server.register([ require('vision'), require('inert'), {register: require('lout')}], function (err) { throw err }); // Add the route server.route({ method: 'GET', path: '/hello/{name}', handler: function (request, reply) { reply(sayhi(request.params.name)) } }) // Start the server server.start(function (err) { if (err) throw err console.log('Server started at ', server.info.uri) })