2

Hello I'm trying to make some Javascript files working on nodeJS everything is well set however here is the error I get :

ReferenceError: navigator is not defined
at C:\Users\blaster\node_modules\mxgraph\javascript\dist\build.js:45:9
at Object.<anonymous> (C:\Users\blaster\Desktop\projet\entrainement_mxgraph\test_mxgraph.js:3:33)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

I try to make the example of code "hello world" under nodeJs for the project of a school, I am quite new in the concept nodeJs and the project javascript, my question is maybe simple or basic but I struggle with that for hours since yesterday

here's my code :

var express = require('express');

var mxgraph = require("mxgraph")({
mxImageBasePath: "./src/images",
mxBasePath: "mxgraph-master/mxgraph-master/javascript/src"
})

var mxEvent = mxgraph.mxEvent;
mxEvent.disableContextMenu(container);

var app = express();

app.get('/', function(req, res) {

    // Checks if the browser is supported
        if (!mxClient.isBrowserSupported())
        {
            // Displays an error message if the browser is not supported.
            mxUtils.error('Browser is not supported!', 200, false);
        }
        else
        {
            // Disables the built-in context menu
            mxEvent.disableContextMenu();
            
            // Creates the graph inside the given container
            var graph = new mxGraph();

            // Enables rubberband selection
            new mxRubberband(graph);
            
            // Gets the default parent for inserting new cells. This
            // is normally the first child of the root (ie. layer 0).
            var parent = graph.getDefaultParent();
                            
            // Adds cells to the model in a single step
            graph.getModel().beginUpdate();
            try
            {
                var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
                var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
                var e1 = graph.insertEdge(parent, null, '', v1, v2);
            }
            finally
            {
                // Updates the display
                graph.getModel().endUpdate();
            }
        }
});

app.listen(8080);

thank's you all.

Yblaster
  • 21
  • 1
  • 2
  • 1
    Looks like you're trying to use a library designed for a web browser environment. Node is not a web browser. – Pointy Jun 25 '20 at 13:51
  • that's what I thought, I will see with my teacher to change technology, thank'sa lot for your quickly reply – Yblaster Jun 25 '20 at 14:05
  • I don't know if this complicates or simplifies your life, but there are some frameworks (e.g. Electron) to use Javascript as desktop app... https://www.electronjs.org/ – Marco Jun 26 '20 at 06:43

0 Answers0