'use strict'; const Hapi = require('hapi'); // 创建服务器实例 const server = new Hapi.Server(); // Specify connections (server available on http://localhost:8000) server.connection({ port: 8000 }); // 添加路线 server.route({ method: 'GET', path:'/hello', handler: function (request, reply) { return reply('hello world'); } }); // 启动服务器 server.start((err) => { if (err) { throw err; } console.log('Server running at:', server.info.uri); });
运行node server.js并在浏览器中打开http:// localhost:8000 / hello。