aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authoramelia <[email protected]>2022-06-17 22:35:50 -0500
committeramelia <[email protected]>2022-06-17 22:35:50 -0500
commit25c18c481666857a3123e08db0bdc541b6cb88b8 (patch)
treefd38ca5eb812c45795b5ace601b68d761a463e60 /index.js
parent1371f48a83bc45bc3c3bbe47ebd12ef4a9b835f9 (diff)
added localhost support
Diffstat (limited to 'index.js')
-rw-r--r--index.js28
1 files changed, 19 insertions, 9 deletions
diff --git a/index.js b/index.js
index f5f5b4e..e64fb0b 100644
--- a/index.js
+++ b/index.js
@@ -1,13 +1,23 @@
-var http = require('http');
-var fs = require('fs');
+var fs = require('fs');
+//express
+var express = require('express');
+var app = express();
+//this dir
+var dir = __dirname;
const PORT=3000;
-
+let t = dir + './crates.json'
fs.readFile('./index.html', function (err, html) {
-
- if (err) throw err;
-
- http.createServer(function(request, response) {
- response.write(html);
- }).listen(PORT);
+//listen
+app.listen(PORT, function () {
+ console.log('listening on port ' + PORT);
+});
+//on request serve index.html
+app.get('/', function (req, res) {
+ res.sendFile('index.html', {root: __dirname })
+})
+app.get('/crates.json', function (req, res) {
+ res.sendFile('crates.json', {root: __dirname })
+})
+
}); \ No newline at end of file