A rich framework for building applications and services
hapi enables developers to focus on writing reusable application logic instead of spending time building infrastructure.
$ npm install hapi
$ npm install hapi
hapi's stability and reliability is empowering these companies today:
See moreAre you using hapi too? Let us know.
Visit us on IRC in #hapi on freenode.
Join us on Slack at hapihour.slack.com (First time? Join here).
Start by creating a package.json:
npm initInstall hapi and save it to your package.json dependencies:
npm install hapi --saveCreate a server.js file with the following contents:
'use strict';
const Hapi=require('hapi');
// Create a server with a host and port
const server=Hapi.server({
host:'localhost',
port:8000
});
// Add the route
server.route({
method:'GET',
path:'/hello',
handler:function(request,h) {
return'hello world';
}
});
// Start the server
async function start() {
try {
await server.start();
}
catch (err) {
console.log(err);
process.exit(1);
}
console.log('Server running at:', server.info.uri);
};
start();
Launch the application by running npm start and open localhost:8000/hello in your browser.