I have started plying with Node.JS very recently. I would like to address your second last line
"How can i play the video on web browser when i connected web server?"
So far I have found two ways to render video/audio on the client's browser using nodejs server. I am going to share code for both ways.
The one way is loading an HTML page on client's browser (index.html where video is already embedded using tag) with video player ready to be played. And second way is sending the video directly as a response from server to your web browser. The latter method may or may not need HTML, depends on how you really want to achieve this.
Instead of using small port number like 1233, I would like to do justice with networking and let's say we want to use 8383 port number.
Method 1: Render an HTML page with video player already embedded to it. I am considering that your webserver.js and index.html files reside in same directory. Here is something which will satisfy your requirement -
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/'));
var ipAddress = process.env.OPENSHIFT_NODEJS_IP;
var port = process.env.OPENSHIFT_NODEJS_PORT || 8383;
app.listen(port, ipAddress);
Run your webserver.js and type http://localhost:8383/index.html on your browser !
Method 2 - If you want to achieve it using require('http") then use following code -
var http = require('http');
fileSystem = require('fs'),
path = require('path');
util = require('util');
http.createServer(function (req, response) {
var filePath = path.join('./', 'b.mp4');
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {
"Content-Type": "video/mpeg",
"content-size": stat.size
});
var readStream = fileSystem.createReadStream(filePath);
readStream.on('data', function (data) {
var flushed = response.write(data);
// Pause the read stream when the write stream gets saturated
if (!flushed)
readStream.pause();
});
response.on('drain', function () {
// Resume the read stream when the write stream gets hungry
readStream.resume();
});
readStream.on('end', function () {
response.end();
});
}).listen(8383);
After running your webserver.js, type http://localhost:8383/.