From 71c4ec6d74a750a8a7bd7a2394259d9824b7f42e Mon Sep 17 00:00:00 2001 From: Nightly Date: Mon, 17 Oct 2022 10:07:07 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + Components/webserver.js | 27 +++++++++++++++++++++++++++ Public/style.css | 3 +++ README.md | 3 +++ Templates/index.ejs | 15 +++++++++++++++ index.js | 2 ++ package.json | 6 ++++++ 7 files changed, 57 insertions(+) create mode 100644 .gitignore create mode 100644 Components/webserver.js create mode 100644 Public/style.css create mode 100644 README.md create mode 100644 Templates/index.ejs create mode 100644 index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/Components/webserver.js b/Components/webserver.js new file mode 100644 index 0000000..46d1f29 --- /dev/null +++ b/Components/webserver.js @@ -0,0 +1,27 @@ +// Import things +const express = require('express'); +const app = express(); +const server = require('http').createServer(app); +const port = process.env.PORT || 3430; + +// Set the templates folder for the thingy +app.set('views', __dirname + '/../Templates'); +app.set('view engine', 'ejs'); + +// Makes it so that the Public folder mounts under / +app.use(express.static(__dirname + '/../Public')); + +// Main page +app.get('/', function(req, res){ + res.render('index'); +}); + +// Simple way to expose a function +exports = module.exports = rws; + +// rws = RunWebServer +function rws() { + server.listen(port, () => { + console.log('✅ Webserver is running ( %d )', port); + }); +}; \ No newline at end of file diff --git a/Public/style.css b/Public/style.css new file mode 100644 index 0000000..1e3d829 --- /dev/null +++ b/Public/style.css @@ -0,0 +1,3 @@ +#cssloaded { + color:deepskyblue; +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f26e1e6 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# nodejs-express-ejs + +Template repo \ No newline at end of file diff --git a/Templates/index.ejs b/Templates/index.ejs new file mode 100644 index 0000000..133d050 --- /dev/null +++ b/Templates/index.ejs @@ -0,0 +1,15 @@ + + + + + + + Hello world! + + + + + +

Hello world!

+ + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..8874219 --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +var rws = require("./Components/webserver.js"); +rws(); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..d9b58df --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "ejs": "^3.1.8", + "express": "^4.18.1" + } +}