require(processing-js) throws Reference Error: Navigator not Found
Asked Answered
A

2

0

I'd like to use processingJS as an npm package in a nodeJS server for deployment on MS Azure. I'm using VS15. I'm having trouble referencing it:

var pjs = require('processing-js');
var http = require('http'),
fs = require('fs');
var port = process.env.port || 1337;

The first line of my code throws

ReferenceError: navigator is not defined 

The research I've done leads me to believe that navigator is some property related to the browser but I'm having trouble finding more information.

I have looked at these resources but wasn't able to come up with a solution:

Require('jquery-ui') in node-webkit produces navigator not found error

https://github.com/tobie/ua-parser/issues/440

http://fredkschott.com/post/2014/06/require-and-the-module-system/

I'd like to be able to precompile processing into javascript.

Thanks in advance.

Angeloangelology answered 20/1, 2016 at 21:12 Comment(0)
W
2

navigator is an object available in a desktop browser by the host environment. (Much like the DOM) -- the javascript language doesn't define the navigator object so V8 (the underlying engine) doesn't provide it and since node isn't a browser, it doesn't implement the navigator object either.

Processing is designed to be used solely in the browser -- either you're going to need to provide a shimmed environment for it in node, or use it in the browser (either headless or not)

Wirra answered 20/1, 2016 at 21:23 Comment(0)
A
0

For anyone looking back on this question wondering how to precompile processingjs code into javascript code, here was my client-side solution:

var sketch = document.getElementById('processing-canvas');
var processingCode = 'some processingJS code as a string';
var jsCode = Processing.compile(processingCode);  // include the processingJS api as well as processingJS in the html page you call this script from
var processingInstance = new Processing(sketch, jsCode);
Angeloangelology answered 22/3, 2016 at 17:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.