showing results for - "if 28req url 3d 3d 3d 22 2fscript js 22 29"
Chandler
05 Nov 2020
1var http = require('http');
2var url = require('url');
3var fs = require('fs');
4var path = require('path');
5
6http.createServer(function(req, res) {
7    if (req.url === '/') {
8        fs.readFile('./index.html', function(err, data) {
9            if (err){
10                throw err;
11            }
12            res.writeHead(200, { 'Content-Type': 'text/html' });
13            res.write(data); 
14            res.end();
15            return;
16        });
17    } else if (req.url === '/script.js') {
18        fs.readFile('./script.js', function (err, data) {
19            if (err) { throw err; }
20            res.writeHead(200, { 'Content-Type': 'text/javascript' });
21            res.write(data);
22            res.end();
23            return;
24        });
25    }
26}).listen(3000);