Skip to content

Instantly share code, notes, and snippets.

@RJ722
Forked from iamareebjamal/basic_server.js
Created January 16, 2017 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RJ722/df63e21d5b6c433945c151bec4438d6c to your computer and use it in GitHub Desktop.
Save RJ722/df63e21d5b6c433945c151bec4438d6c to your computer and use it in GitHub Desktop.
Basic Node Server to capture images and display in multipart using boundary
/* Node Server
* Captures image and displays them using multipart and boundary headers
* 16th Jan 2016
* Author : Areeb Jamal, Rahul Jha
*/
var fs = require('fs'),
http = require('http'),
express = require('express'),
NodeWebcam = require("node-webcam");
var opts = {
width: 1280,
height: 720,
delay: 0,
quality: 100,
output: "jpeg",
verbose: false
}
var Webcam = NodeWebcam.create(opts);
app = express();
var server = http.createServer(app);
app.use(express.static('app'));
app.get('/', function(req, res) {
res.writeHead(200, {
'Content-Type': 'multipart/x-mixed-replace; boundary=myboundary'
});
var capture = function() {
Webcam.capture("my_picture");
fs.readFile('./' + 'my_picture.jpg', function(err, content) {
if (err) {
console.log(err);
return;
}
res.write("--myboundary\r\n");
res.write("Content-Type: image/jpeg\r\n");
res.write("\r\n");
res.write(content, 'binary');
res.write("\r\n");
});
setTimeout(capture, 100);
};
capture();
});
var port = process.env.PORT || 8080;
server.listen(port, function() {
console.log('Listening on ' + port);
});
@RJ722
Copy link
Author

RJ722 commented Jan 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment