Hapi.js is an open-source framework that provides us with different objects and methods for abstracting HTTP, just you need to install hapi by $ npm install hapi --save
, and make connection with server to used it.
After call hapi, and make connection with server, we can use route that contains object of (method, path, and handler)
server.route({
method : 'GET',
path : '/{userName}',
handler : function (request,reply){
reply('Hello World !' + request.params.userName);
}
});
$ npm install vision --save
$ npm install handlebars --save
vision module contains views that used for add file (html,css,..) reply.view('file_name'), and in handlebars we can use the template to pass variable from js into html file
server.views({
engines : {
html : require('handlebars')
},
relativeTo : __dirname,
path : 'templates'
});
We can add static content without vision and handlebars, just by reply what we went as in example above.