node send file
var http = require('http'),
fileSystem = require('fs'),
path = require('path');
http.createServer(function(request, response) {
var filePath = path.join(__dirname, 'myfile.mp3');
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size
});
var readStream = fileSystem.createReadStream(filePath);
// We replaced all the event handlers with a simple call to readStream.pipe()
readStream.pipe(response);
})
.listen(2000);app.get('/', function(req, res){
res.sendFile('index.html');
});
Also in JavaScript:
- javascript check if two date are ugual
- checkbox default value and checked value get in jquery
- jquery script tag
- js query string
- javascript operator double not
- read more css js
- javascript date countdown
- ionic react use yarn
- number to string javascript
- input text react 2020
- location javascript redirect
- vue store access state in actions
- returned data has p tags react
- get and set es6
- javascript canvas reset transform
- react get data attribute from element
- how to create my own filter in js
- swift convert array to json
- javascript group by property array of objects
- close current tab javascript
- javascript get referrer
- js isset
- js yesterday date
- ban someone discord js