I am still quite a novice to nodejs and web development in general. I am using a package called "neovis": https://github.com/neo4j-contrib/neovis.js/ to create visualisations of my data in my neo4j database. It is currently imported via CDN in the frontend and everything runs from the frontend.
script src="https://rawgit.com/neo4j-contrib/neovis.js/master/dist/neovis.js"></script>
Although it works great, I want to use it on the server, so I don't have to expose my database credentials on the frontend. I installed the package via npm but it throws some error when I try to "require" it in nodejs.
var express = require('express');
var neo4j = require('neo4j-driver');
var NeoVis = require('neovis.js') // this causes the error
var app = express();
app.use(express.static('public'))
// home route returns rendered html content
app.get("/", (req, res) => {
res.sendFile(__dirname + "/frontend/index.html");
});
produces error:
ReferenceError: window is not defined
Source: /usr/src/nodejs/node_modules/neovis.js/dist/neovis.js:1
Since I have no idea how to solve this error as it is coming from the neovis package, I was wondering if it is possible to import the CDN (like in the frontend) on the nodejs backend as that seems to work fine? Or is this a stupid question?
After googling for another hour I finally found the following issue on the neovis github: https://github.com/neo4j-contrib/neovis.js/issues/101.
Indeed it seems like neovis can't be used on a server nor render an already fetched graph data object. So nothing we can do for now.