From 25c18c481666857a3123e08db0bdc541b6cb88b8 Mon Sep 17 00:00:00 2001 From: amelia Date: Fri, 17 Jun 2022 22:35:50 -0500 Subject: added localhost support --- index.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'index.js') 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 -- cgit v1.2.3