0

I'm trying to figure out how to import data from nodejs to html webpage. I explain my problem clearly:

I have 3 files:

  • index.html
  • processData.js
  • plot.js

In processData.js there is a Nodejs function that retrieve from a mongoDB database some data and return them into an array. The problem is that I need to import module processData in plot.js to use it ( perhaps using chart.js). It's all day that I try but there's the problem that in pure javascript I cannot import Nodejs modules and in NodeJS I cannot use window

Anyone can help me?

  • You want to make an ajax request to your node.js server function to retrieve the data. – Adrian Nov 09 '18 at 16:48
  • Possible duplicate of [Basic Ajax send/receive with node.js](https://stackoverflow.com/questions/6011984/basic-ajax-send-receive-with-node-js) – Adrian Nov 09 '18 at 16:48
  • is there a way to do that without ajax? – TheJoe94 Nov 09 '18 at 17:00
  • Yes, you can add the results of `processData.js` to `index.html` before returning it to the browser. Then `chart.js` can run on the client-side and use the data that you wrote to `index.html`. – Will Nov 09 '18 at 17:31
  • how can I add the results to index.html? – TheJoe94 Nov 09 '18 at 17:40

0 Answers0