diff options
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 |