首页 > Windows开发 > 详细

[Hapi.js] Up and running

时间:2016-02-27 18:02:06      阅读:243      评论:0      收藏:0      [点我收藏+]

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

 

[Hapi.js] Up and running

原文:http://www.cnblogs.com/Answer1215/p/5223187.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!