0.0.4 • Published 7 years ago
xvi-express v0.0.4
npm-xvi-express
Express Server
//Add package
const Server = require('xvi-express');
//Create instance of the server
var instance = new Server({
"protocol": "http",
"port": 3000,
"socketIO": true,
"publicFolderPath": 'public/',
"uploadFolder": 'uploads/'
});
//test function
async function test() {
try {
await instance.start();
//Add route on server
instance.addRoute({
name: 'mainRoute', //name
path: '/main-route', //path of the route
prefix: 'main', //for log purpose
type: 'get', //or post
handler: async function (req, res) { // handler
//res.send(true);
return true;
}
});
//Add IO event on server
instance.addIOEvent({
name: 'testHandler',
handler: async function (args) {
console.log(args);
//this is a IO event
}
});
} catch (err) {
console.log(err);
}
}
test();
Will output:
170918-213053 | debug.ExpressServer | canStart = true
170918-213053 | debug.ExpressServer | start
170918-213053 | debug.ExpressServer | setServer
170918-213053 | debug.ExpressServer | Started Server on port 3000
170918-213053 | debug.ExpressServer | Set Route main, mainRoute on /main-route, type get
170918-213108 | debug.ExpressServer | GET on: main.mainRoute