diff options
author | amelia <[email protected]> | 2022-06-17 22:35:50 -0500 |
---|---|---|
committer | amelia <[email protected]> | 2022-06-17 22:35:50 -0500 |
commit | 25c18c481666857a3123e08db0bdc541b6cb88b8 (patch) | |
tree | fd38ca5eb812c45795b5ace601b68d761a463e60 /index.js | |
parent | 1371f48a83bc45bc3c3bbe47ebd12ef4a9b835f9 (diff) |
added localhost support
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -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 |