Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

http node

var fs  = require("fs")
var http  = require("http")

//in this example, I try to show an image
http.createServer((req, res) => {

    fs.readFile(`./images/${req.url}.jpg`, (err, data) => {
        if(err) {
            res.writeHead(404, {'Content-Type': 'text/plain'})
            res.end('Img not found')
        } else {
            res.writeHead(200, {'Content-Type': 'image/jpg'})
            res.end(data)
        }
    })
//change 3000 if you prefer
}).listen(1337, 'localhost')
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #http #node
ADD COMMENT
Topic
Name
6+7 =