0

I have a function NodeJS application which converts video files and puts them in a 'converted' directory. I am using the express, http and multer modules. The problem I'm having is downloading the completed videos. Shouldn't I be able to see, load the completed video in a browser if I simply point to it?

ie when I enter the following

http://localhost:8080/converted/converted.avi

I get

Cannot GET /converted/converted.avi

The complete header portion of my node app is

var express = require('express');
var app = express();
    var multer  = require('multer'),
           fs = require('fs'),
       ffmpeg =  require('./lib/fluent-ffmpeg');

    var server = require('http').createServer(app);
    var io = require('socket.io').listen(server,{transports:['flashsocket', 'websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']});

    var port = Number(8080);
    server.listen(port);

    app.use(multer({ dest: './uploads/'}));

Probably not relevant since there are other issues at play but this is the actual code I am using for an Adobe AIR client to do the actual downloading
(reference http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html)

 _urlLoader = new URLLoader();
                _urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
                _urlLoader.addEventListener(Event.COMPLETE,
                    function(e:Event):void
                    {
                        var air:File = File.desktopDirectory.resolvePath("converted.mp4");
                        //var file:File = File.desktopDirectory.resolvePath("AIR Test");
                        var fs:FileStream = new FileStream();
                        fs.open(air, FileMode.WRITE);
                        fs.writeBytes(_urlLoader.data);
                        fs.close();
                        air.downloaded = true;
                    });

Using the following simple setup for express to serve a static directory SHOULD work but

var express = require('express');
var app = express();

console.log('static and __dirname = '+__dirname)
app.use(express.static(__dirname+'/public'));

app.listen(process.env.PORT || 3000);

when i drop a simple index.html in the server public folder I still only get the following in a browser...

Cannot GET /public/index.html

Bachalo
  • 6,965
  • 27
  • 95
  • 189

1 Answers1

2

Node.js web servers do not serve directories unless you explicitly tell them to.

If you're using Express, use the static() middleware to tell it to serve that directory.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • should work but even when I try setting up a static directory I see Cannot GET /public/index.html. See my edited question above... – Bachalo Feb 04 '15 at 16:44
  • @eco_bach just access `/index.html` – laggingreflex Feb 04 '15 at 16:58
  • @eco_bach: `static()` will serve files directly in the root (unless you tell it otherwise). There is no reason for `public` to appear in the URL. – SLaks Feb 04 '15 at 17:16