From d75ee931841f872f58f3419712d7e9177a924a6c Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 2 Feb 2019 14:18:15 -0500 Subject: [PATCH] Started project by creating simple user functionality methods and set up node dependencies. --- fileIO.js | 26 ++++++++++++++++++++++++++ server.js | 24 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 fileIO.js diff --git a/fileIO.js b/fileIO.js new file mode 100644 index 0000000..02fae92 --- /dev/null +++ b/fileIO.js @@ -0,0 +1,26 @@ + +/** Used to read and write files from disk */ +const fs = require('fs'); + +module.exports = + { + writeJSONToFile: function(fileName, jsonObject) + { + const json = JSON.stringify(jsonObject, null, 4); + fs.writeFile(fileName, json, 'utf8', function() + { + console.log("Wrote to " + fileName); + }); + }, + + + /** + * + * @param fileName + * @returns {any} + */ + getFileAsJSON: function(fileName) + { + return JSON.parse(fs.readFileSync(fileName, 'utf8')); + } + }; diff --git a/server.js b/server.js index e69de29..2bb53a9 100644 --- a/server.js +++ b/server.js @@ -0,0 +1,24 @@ +/** express app for routing */ +const express = require("express"); + +/**session data for login and storing preferences*/ +const session = require('express-session'); + +const fileIO = require('./fileIO'); + + +const app = express(); + + +app.use(express.urlencoded()); +app.use(express.json()); // if needed + +/**Initializes sessions for login */ +app.use(session({ secret: "sessionSecret", cookie: { maxAge: 6000000 }})); + +/** Template engine */ +const whiskers = require('whiskers'); + + +const CONFIG_FILE_NAME = "conf.json"; +const config = fileIO.getFileAsJSON(CONFIG_FILE_NAME); \ No newline at end of file