Installing hapi.
In this section we will learn how to install hapi.
- Create a new directory xyz. Run: npm init and generate a package.json file. Run: npm install –save hapi, this command installs hapi, and also saves it in your package.json file as a dependency.Done, Now you use hapi server in your project.
Creating new server.
In this section we will learn how to create a server in hapi.
- Create a new file(xyz.js) in dir xyz.
write following code.
[cc lang=”javascript”]var Hapi = require(‘hapi’);
var server = new Hapi.Server();
server.connection({ port: 3000 });
server.start(function () {
console.log(‘Server running at:’, server.info.uri);
});
[/cc]
- In first line, firstly we need to requiring our hapi module so, we define a variable named server and set it’s value to a new Hapi server.
- In second line, we add a connection to the server, passing in a port number to listen on.
- In third line,we need to start our server by using the server.start() method
In this blog we will learn how to install hapi and how to create server in hapi.
Installing hapi.
In this section we will learn how to install hapi.
- Create a new directory xyz. Run: npm init and generate a package.json file. Run: npm install –save hapi, this command installs hapi, and also saves it in your package.json file as a dependency.Done, Now you use hapi server in your project.
Creating new server.
In this section we will learn how to create a server in hapi.
- Create a new file(xyz.js) in dir xyz.
write following code.
[cc lang=”javascript”]var Hapi = require(‘hapi’);
var server = new Hapi.Server();
server.connection({ port: 3000 });
server.start(function () {
console.log(‘Server running at:’, server.info.uri);
});
[/cc]
- In first line, firstly we need to requiring our hapi module so, we define a variable named server and set it’s value to a new Hapi server.
- In second line, we add a connection to the server, passing in a port number to listen on.
- In third line,we need to start our server by using the server.start() method