nodejs-express-ejs/Components/webserver.js

27 lines
680 B
JavaScript
Raw Normal View History

2022-09-07 09:10:03 +02:00
// Import things
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const port = process.env.PORT || 3430;
2022-09-07 09:12:24 +02:00
// Set the templates folder for the thingy
2022-09-07 09:10:03 +02:00
app.set('views', __dirname + '/../Templates');
app.set('view engine', 'ejs');
2022-09-07 09:12:24 +02:00
// Makes it so that the Public folder mounts under /
2022-09-07 09:10:03 +02:00
app.use(express.static(__dirname + '/../Public'));
// Main page
app.get('/', function(req, res){
2022-09-07 09:12:24 +02:00
res.render('index');
2022-09-07 09:10:03 +02:00
});
// Simple way to expose a function
exports = module.exports = rws;
2022-09-07 09:12:51 +02:00
// rws = RunWebServer
2022-09-07 09:10:03 +02:00
function rws() {
server.listen(port, () => {
console.log('✅ Webserver is running ( %d )', port);
});
};