I am looking to read audi/video stream using nodejs, haven't found any thing that explains how to achieve this.
Please advice how this can be done
Thanks
VidStreamer.js A simple streamer for Flash and HTML5-style videos. Supports HTTP pseudostreaming and works with JW Player's bitrate switching.
you can install it using
npm install vid-streamer
then give your audio/video files path in config/vidStreamer.json
if it not work then clone the https://github.com/meloncholy/vid-streamer.git repository and make appropriate configuration. Sample configuration
{
"mode": "development",
"forceDownload": false,
"random": false,
"rootFolder": "/path/to/videos/",
"rootPath": "videos/",
"server": "VidStreamer.js/0.1.4"
}
To make a standalone video streamer, try something like this
var http = require("http");
var vidStreamer = require("vid-streamer");
var app = http.createServer(vidStreamer);
app.listen(3000);
console.log("VidStreamer.js up and running on port 3000");
Related
Ok I've been playing around with nodejs, expressjs and socket.io to create some applications. But now im coming to the stage where i want to take things a bit further.
I have noticed a few node apps using PHP for twitter auth on their client side. When I attempt to rename my client.html file to client.php and restart the server it throws up a blank page with this
Cannot GET /
How do would serve php files or would i do twitter auto using js?
This is my NodeJS server.js
var http = require('http'),
express = require('express');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.use(express.static(__dirname + '/public'));
});
app.listen(1234);
console.log("server started on port :1234");
As already noted, node.js itself won't interpret php files for you. Available options are:
have nginx in front of node and reverse proxy all request you want to process in node from it
proxy php requests from node to php-capable server
spawn php process on each request in node
make fastcgi link to php-fastcgi using node fastcgi protocol parser
Uh, skip PHP entirely and integrate everyauth into your app.
PHP-EXPRESS should do. Just install the package and follow the docs.
https://www.npmjs.com/package/php-express
I have a little NodeExpress server and when I try to make a request to the server it returns a 403 error
I have installed Cors and used it and tried with chrome browser and Postman as 2 clients and got the same denied error
var express = require('express')
var cors = require('cors')
var app = express()
app.use(cors())
app.get('/', function (req, res, next) {
res.json({msg: 'This is CORS-enabled for all origins!'})
})
app.listen(80, function () {
console.log('CORS-enabled web server listening on port 80')
})
I was having this having this problem with using firebase serve on MacBook Pro (14-inch, 2021), Apple M1 Pro, macOS Monterey 12.3
UPDATE:
so apparently the reason was
macOS Monterey introduced AirPlay Receiver running on port 5000. This prevents your web server from serving on port 5000. Receiver already has the port.
so the solution proposed by the answer quoted above, was to either turn off the AirPlay Receiver, or to run your app on another port.
if you are running your app using firebase serve, You can change the port by following this approach:
source
firebase.json file doesn't work with the the firebase serve command.
You have to use the firebase emulators:start command.
If you want to keep using firebase serve then it should be use like
in:
firebase serve --only hosting --port=5002
OLD ANSWER:
Not a sufficient answer, but I was able to bypass this by entering 127.0.0.1 instead of localhost. I don't think this is the best answer, neither I am satisfied with it. I'll definitely come back later and update the answer once I find a better answer.
just use another port e.g. 5100
"sampleApp": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5100",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Sometimes I had the same issue when developing FLASK application on Monterey and using Chrome.
A restart of Chrome always solved the issue. I suppose that not stopping the application properly is the root cause in my case.
I've just encountered this issue. My stack was Node + Express
With this stack, above solution works as well.
All I had to do was to change the porn number:
app.listen(5000); // does not work
app.listen(8000); // all good :)
I am trying to learn the basics of node.js and socket.io. I have been using this tutorial http://tutorialzine.com/2012/08/nodejs-drawing-game/
the full code for this problem can be seen in the link above.
I can create a basic web server with node.js and get it to return hello world so I am sure that's installed correctly. However upon installing these packages
npm install socket.io#0.9.10 node-static
and setting up the serverside js as instructed
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
nstatic = require('node-static');
var fileServer = new nstatic.Server('./');
app.listen(8080);
I just get this prompt in my cmd and a constantly hanging web browser, instead of the html page that is meant to be served.I think I may have messed up an install but upon looking at the list of installed packages in npm it states both socket.io and node-static are present.
The code below should be more effective?, it looks like you are missing the handler part. The response must be explicitly ended or browser requests will hang forever like you are seeing. The node-static file.serve method manages the request once you pass it down. The source for .serve is here: https://github.com/cloudhead/node-static/blob/master/lib/node-static.js#L164
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
nstatic = require('node-static');
app.listen(8080);
var file = new nstatic.Server('./');
function handler(request, response) {
request.addListener('end', function () {
file.serve(request, response);
}).resume();
}
console.log('started')
Note also that the default file to serve to responses at / is index.html.
I've been trying to make a server that can visualize music (This is what I have so far). That's been successful but I want to try and make it work with youtube videos, and I've found a lot of repositories on github for youtube video to audio conversion that make this reasonably doable, but in order to deploy a server on heroku that can host temporary audio files of youtube videos in the format that I want, I'd need to include ffmpeg in a buildpack and I'm not sure how to go about doing that. This is the heroku buildpack for node.js but I don't really understand how it works.
TL;DR: What steps would I need to follow after forking the heroku-buildpack-nodejs repository on github in order to successfully deploy a node.js server to heroku and run this code?
var conversionProcess = child_process.spawn(
'ffmpeg',
['-i', 'some_youtube_audio.mp3', 'some_youtube_audio.webm'],
{
cwd: __dirname + '/tmp'
}
);
The documentation for this function is on the node.js API, by the way.
you should use the multipack https://github.com/ddollar/heroku-buildpack-multi
then use the node buildpack as well as an ffmpeg buildpack https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest
This is my first time with node.js. I get it to display the index.html, but it doesn't display the images on the site or anything else, it ONLY shows the basic html stuff. Here's how I set it up.
There's no apache, php or anything else on the server, just ubuntu, proftp and node(and curl and the other dependencies). I made the main directory for the node files /var/nodeFiles and the directory for the html/site files is /var/nodeFiles/www
so for my node server file I did it like this:
var http = require('http'),
fs = require('fs');
fs.readFile('/var/nodeFiles/www/index.html', function (err, html) {
if (err) {
throw err;
}
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(80);
});
this works, but it ONLY shows the index.html file and NOTHING attached to it, so no images, no effects or anything that the html file should display. The files and directories are all correct, I've double checked and the permissions of the folders are correct. So what else do I have to do to get node to display the rest of the site?
I hope I've explained my self correctly, I was told this is the place to ask development questions.
Thank you for taking the time to read this.
but it ONLY shows the index.html file and NOTHING attached to it, so no images,
no effects or anything that the html file should display.
That's because in your program that's the only thing that you return to the browser regardless of what the request looks like.
You can take a look at a more complete example that will return the correct files for the most common web pages (HTML, JPG, CSS, JS) in here https://gist.github.com/hectorcorrea/2573391
Also, take a look at this blog post that I wrote on how to get started with node. I think it might clarify a few things for you: http://hectorcorrea.com/blog/introduction-to-node-js
Check this basic code to setup html server. its work for me.
var http = require('http'),
fs = require('fs');
fs.readFile('./index.html', function (err, html) {
if (err) {
throw err;
}
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(8000);
});
This did the trick for me:
var express = require('express'),
app = express();
app.use('/', express.static(__dirname + '/'));
app.listen(8080);
If your goal is to simply display some static files you can use the Connect package. I have had some success (I'm still pretty new to NodeJS myself), using it and the twitter bootstrap API in combination.
at the command line
:\> cd <path you wish your server to reside>
:\> npm install connect
Then in a file (I named) Server.js
var connect = require('connect'),
http = require('http');
connect()
.use(connect.static('<pathyouwishtoserve>'))
.use(connect.directory('<pathyouwishtoserve>'))
.listen(8080);
Finally
:\>node Server.js
Caveats:
If you don't want to display the directory contents, exclude the .use(connect.directory line.
So I created a folder called "server" placed index.html in the folder and the bootstrap API in the same folder. Then when you access the computers IP:8080 it's automagically going to use the index.html file.
If you want to use port 80 (so just going to http://, and you don't have to type in :8080 or some other port). you'll need to start node with sudo, I'm not sure of the security implications but if you're just using it for an internal network, I don't personally think it's a big deal. Exposing to the outside world is another story.
Update 1/28/2014:
I haven't had to do the following on my latest versions of things, so try it out like above first, if it doesn't work (and you read the errors complaining it can't find nodejs), go ahead and possibly try the below.
End Update
Additionally when running in ubuntu I ran into a problem using nodejs as the name (with NPM), if you're having this problem, I recommend using an alias or something to "rename" nodejs to node.
Commands I used (for better or worse):
Create a new file called node
:\>gedit /usr/local/bin/node
#!/bin/bash
exec /nodejs "$#"
sudo chmod -x /usr/local/bin/node
That ought to make
node Server.js
work just fine
You can simply use
res.senFile('PATH_TO_FILE');