Setup server with basic configuration

This commit is contained in:
ruihildt 2019-07-31 09:14:12 +02:00
parent 79205eb95e
commit effa3ef442
2 changed files with 25 additions and 0 deletions

11
api/server.js Normal file
View File

@ -0,0 +1,11 @@
const express = require("express");
const helmet = require('helmet');
const cors = require('cors');
const server = express();
server.use(helmet());
server.use(express.json());
server.use(cors());
module.exports = server;

14
index.js Normal file
View File

@ -0,0 +1,14 @@
require("dotenv").config();
const server = require("./api/server");
server.get("/", (req, res) => {
res.json({
message: `API server for Sleep Tracker running. :)`
});
});
const PORT = process.env.PORT;
server.listen(PORT, () => {
console.log(`Listening on port ${PORT}...`);
});