setup backend

This commit is contained in:
Wilkozx 2024-08-04 18:02:22 +01:00
parent 6ada601a81
commit 0cad380e49
3 changed files with 37 additions and 1 deletions

22
backend/index.js Normal file
View File

@ -0,0 +1,22 @@
require('dotenv').config();
const express = require('express');
// Invoke express app
const app = express();
// Middleware to log requests
app.use((req, res, next) => {
let time = new Date().toLocaleTimeString();
console.log(time + ' | Request received | path: ' + req.path + ' | method: ' + req.method);
next();
});
// Setup Route for Testing
app.get('/', (req, res) => {
res.json({'message': 'Hello World!'});
});
// Listen on port set in .env
app.listen(process.env.PORT, () => {
console.log('Server is listening on port ' + process.env.PORT);
});

View File

@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2", "express": "^4.19.2",
"mongoose": "^8.5.2", "mongoose": "^8.5.2",
"socket.io": "^4.7.5" "socket.io": "^4.7.5"
@ -228,6 +229,17 @@
"npm": "1.2.8000 || >= 1.4.16" "npm": "1.2.8000 || >= 1.4.16"
} }
}, },
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/ee-first": { "node_modules/ee-first": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",

View File

@ -3,13 +3,15 @@
"version": "1.0.0", "version": "1.0.0",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon index.js"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"description": "", "description": "",
"dependencies": { "dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2", "express": "^4.19.2",
"mongoose": "^8.5.2", "mongoose": "^8.5.2",
"socket.io": "^4.7.5" "socket.io": "^4.7.5"