Slip 10
a. Create a Node.js Application to download jpg image from the Server. [Marks 15]
const http=require('http')
const fs=require('fs')
http.createServer((req,res)=>{
const files=fs.createReadStream('Tulips.jpg')
res.writeHead(200,{'Content-disposition':'attachment;filename:Tulips.jpg'})
files.pipe(res)
}).listen(5000)
console.log("Image is download");
/* Output*/
//first install http
C:\Users\NEW\nodex>npm i http
npm WARN nodex@1.0.0 No description
npm WARN nodex@1.0.0 No repository field.
+ http@0.0.1-security
added 1 package and audited 12 packages in 3.915s
found 0 vulnerabilities
C:\Users\NEW\nodex>node slip10a.js
Image is download
^C
//Open crome browser and type localhost:5000 on addressbar to see image is downloading
No comments:
Post a Comment