Browse Source

Created basic utilities for interacting with node js.

pull/11/head
Jeffery Russell 5 years ago
parent
commit
44fce75f1e
4 changed files with 71 additions and 4 deletions
  1. +1
    -1
      GraphTest.html
  2. +33
    -0
      configManager.js
  3. +32
    -0
      fileIO.js
  4. +5
    -3
      server.js

+ 1
- 1
GraphTest.html View File

@ -34,7 +34,7 @@
<body>
<h2 id="graphLabel"></h2>
<div id="myGraph" style="width:100%"></div>
<div id="myGraph"></div>
<script>
createFriendsGraph("jrtechs", "myGraph", "graphLabel");

+ 33
- 0
configManager.js View File

@ -0,0 +1,33 @@
const fileIO = require('./fileIO');
const CONFIG_FILE_NAME = "conf.json";
const config = fileIO.getFileAsJSON(CONFIG_FILE_NAME);
module.exports=
{
getConfiguration: function()
{
return config;
},
syncToDisk: function()
{
fileIO.writeJSONToFile(CONFIG_FILE_NAME, config);
},
getPort: function()
{
return config.port;
},
getClientID: function()
{
return config.clientID;
},
getClientSecret: function()
{
return config.clientSecret;
}
};

+ 32
- 0
fileIO.js View File

@ -0,0 +1,32 @@
/** 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(module.exports.getFile(fileName));
},
getFile: function(filename)
{
return fs.readFileSync(filename, 'utf8');
}
};

+ 5
- 3
server.js View File

@ -19,10 +19,12 @@ app.use(session(
app.use(express.urlencoded()); //for easy retrieval of post and get data
app.use(express.json());
app.use(express.static('css'));
app.use(express.static('js'));
app.use(express.static('img'));
app.use(express.static(__dirname,'css'));
app.use(express.static(__dirname, 'js'));
app.use(express.static(__dirname, 'img'));
app.use(express.static('html'));
app.use(express.static(__dirname, 'fonts'));
const routes = require('./routes');
app.use('/', routes);

Loading…
Cancel
Save