Reputation: 21
i'm trying to orgnize the a hapi folder i added the database also the route but i cant seem to find a way to add the controller , so how i can make it so i can use controller instead of adding all the code in the router thank you so much
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: ""
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
module.exports = con
Routes
"use strict";
const Path = require("path");
module.exports = [
{
method: 'GET',
path: '/',
handler: (request, h) => {
return 'Hello World!';
}
}
];
main.js
'use strict';
const Hapi = require('@hapi/hapi');
const Routes = require("./lib/routes");
const db = require('./config/db')
const init = async () => {
const server = Hapi.server({
port: 3000,
host: 'localhost'
});
server.route(Routes);
await server.start();
console.log('Server running on %s', server.info.uri);
};
db.connect
process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});
init();
Upvotes: 2
Views: 333