[flocking] Error: Loading files from URLs is not currently supported in Node.js AND correct node version

Colin Clark colin at colinclark.org
Fri Mar 3 17:13:21 UTC 2017

Hi James,

It looks like you're using Flocking in Node.js on Windows. There is quite an awful bug in Flocking that causes audio files to fail to load from the file system on Windows in Node.js. Unfortunately this bug means that any of the audio file-related demos in Flocking are not currently functional on Windows. The error message you're receiving is, as you can tell, somewhat misleading—apologies for the confusion.


This bug is slated to be fixed for the upcoming 0.2.0 release, and I'll try to fast track a fix if it's holding you up. 

In the meantime, in your own applications, I think you will have to manually load your audio file into an ArrayBuffer, have Flocking parse it, and then register the resulting buffer with the Flocking environment. I'm travelling at the moment and don't have access to a Windows machine, but here's roughly what the code will look like:

var fs = require("fs"),
      environment = flock.init();

function loadAudioFile(id, path) {
    fs.readFile("<your file path>", function (err, data) {
        // Don't forget to handle an error case, too!

            rawData: data.buffer,
            type: "wav", // Flocking on Node.js only currently supports .wav or .aiff files
            success: function (bufferDesc) {
                bufDesc.id = id;

            error: function (e) { // Handle a decoding error.}

You'd then invoke this like this:

loadAudioFile("hillier-first-chord", "C:\\work\\Flocking\\demos\\nodejs/../../demos/shared/audio/hillier-first-chord.wav");

You can then just refer to your buffer by ID in your synthDef, omitting the "url" option:

"buffer": {
    "id": "hillier-first-chord"

As for Node.js versions, you're right—the documentation is contradictory. I'll update it to reflect the latest versions. I only actively test on the latest LTS releases of Node.js; your mileage may vary on older or newer releases. Your copy of Node.js 6.10 should be just fine.

Until 0.2.0 is released, I recommend using the "0.2.0-dev.20170206T221943Z.fb09a52" dev release with Node.js (or "master" from Github).

I hope this helps,


> On Mar 3, 2017, at 1:55 AM, james bromley <james.a.bromley at gmail.com> wrote:
> I'm getting the above error when running some of the node.js examples, stack at end of file.
> Literally nothing on google about this error. Since I am running v.6.10.0 of node.js maybe this is the problem, as there is a contradiction in help files about which version is supported
> Here https://github.com/colinbdclark/Flocking#compatibility <https://github.com/colinbdclark/Flocking#compatibility> says Node 6.x
> This file https://github.com/colinbdclark/Flocking/blob/master/docs/nodejs.md <https://github.com/colinbdclark/Flocking/blob/master/docs/nodejs.md> says 0.12.x and 4.2.x.
> Is the problem too late a version of Node.js?
> Many thanks for any help
> Error: Loading files from URLs is not currently supported in Node.js.
>     at flock.net.readBufferFromUrl (C:\work\Flocking\src\nodejs\audio-system.js:71:11)
>     at Object.flock.audio.loadBuffer (C:\work\Flocking\src\audiofile.js:204:9)
>     at Object.flock.audio.decode (C:\work\Flocking\src\audiofile.js:239:21)
>     at flock.bufferSource.get (C:\work\Flocking\src\buffers.js:331:29)
>     at invokeInvoker [as get] (C:\work\Flocking\node_modules\infusion\src\framework\core\js\FluidIoC.js:1730:29)
>     at Function.flock.parse.bufferForDef.resolveDef (C:\work\Flocking\src\parser.js:379:20)
>     at Object.flock.parse.bufferForDef (C:\work\Flocking\src\parser.js:324:38)
>     at Object.that.onBufferInputChanged (C:\work\Flocking\src\ugens\core.js:384:29)
>     at Object.that.onInputChanged (C:\work\Flocking\src\ugens\granular.js:125:18)
>     at Object.that.init (C:\work\Flocking\src\ugens\granular.js:151:18)
>     while constructing component of type flock.synth with arguments {
>     "0": {
>         "synthDef": {
>             "ugen": "flock.ugen.writeBuffer",
>             "options": {
>                 "duration": 15,
>                 "numOutputs": 1
>             },
>             "buffer": "recording",
>             "sources": {
>                 "id": "granulator",
>                 "ugen": "flock.ugen.triggerGrains",
>                 "buffer": {
>                     "id": "hillier-first-chord",
>                     "url": "C:\\work\\Flocking\\demos\\nodejs/../../demos/shared/audio/hillier-first-chord.wav"
>                 },
>                 "centerPos": {
>                     "ugen": "flock.ugen.lfNoise",
>                     "freq": 10,
>                     "options": {
>                         "interpolation": "linear"
>                     },
>                     "mul": {
>                         "ugen": "flock.ugen.bufferDuration",
>                         "buffer": "hillier-first-chord",
>                         "mul": 0.9,
>                         "add": 0.1
>                     }
>                 },
>       .... [output suppressed at 1024 chars - for more output, increase fluid.logObjectRenderChars]
> --
> Stickle app (Android)
> www.ergle.com <http://www.ergle.com/>
> Ergle research: https://www.facebook.com/ergleresearch <https://www.facebook.com/ergleresearch>
> LinkedIn: http://uk.linkedin.com/pub/james-bromley/9/736/361/ <http://uk.linkedin.com/pub/james-bromley/9/736/361/>
> Blog: http://jamesabromley.wordpress.com <http://jamesabromley.wordpress.com/>
> Music: https://soundcloud.com/james-bromley-1 <https://soundcloud.com/james-bromley-1>
> The doer alone learneth - Friedrich Nietzsche
> _______________________________________________
> flocking mailing list
> flocking at lists.idrc.ocad.ca
> http://lists.idrc.ocad.ca/mailman/listinfo/flocking

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idrc.ocad.ca/pipermail/flocking/attachments/20170303/da0eb4c3/attachment-0001.html>

More information about the flocking mailing list