[Hapi.js] Up and running

hapi is a rock solid server framework for Node.js. Its focus on modularity and configuration-over-convention makes it the perfect match for any size development team. 

Install:

npm install --save hapi

index.js

'use strict'
var Hapi = require( 'hapi' );

var server = new Hapi.Server();
server.connection( {
    host: 'localhost',
    port: 8000
} );

server.route( {
    method: 'GET',
    path: '/',
    handler: function ( request, reply ) {
        reply( 'hello hapi!' )
    }
} );

server.route( {
    method: 'GET',
    path: '/{name}',
    handler: function ( request, reply ) {
        reply( "hello " + request.params.name + "!" );
    }
} );

server.start( function () {
    console.log( 'Started at:', server.info.uri )
} );

RUN:

node index.js
原文地址:https://www.cnblogs.com/Answer1215/p/5223187.html