[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
上一篇:Java部署项目命令学习小结


下一篇:PHP获取中文首字母的函数