[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

 

posted @ 2016-02-27 17:04  Zhentiw  阅读(220)  评论(0编辑  收藏  举报