Skip to content

Instantly share code, notes, and snippets.

@mikhailbot
Last active April 1, 2017 18:57
Show Gist options
  • Save mikhailbot/9132a90bf6dabf8b588ffead5879909d to your computer and use it in GitHub Desktop.
Save mikhailbot/9132a90bf6dabf8b588ffead5879909d to your computer and use it in GitHub Desktop.
Hapi Registration Error
{
"scripts": {
"start": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"h2o2": "^5.4.0",
"hapi": "^16.1.1",
"joi": "^10.3.4",
"wreck": "^12.0.0"
},
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-hapi": "^10.0.0",
"eslint-plugin-hapi": "^4.0.0",
"nodemon": "^1.11.0"
}
}
'use strict';
const Hapi = require('hapi');
// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: process.env.PORT || 8000
});
// Add the route
server.route({
method: 'GET',
path: '/hello',
handler: function (request, reply) {
return reply('hello world');
}
});
// Register plugins
server.register(require('joi'), (err) => {
if (err) {
throw err;
}
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment