I\'ve been trying to invoke D3 within Node.js. I tried firstly to import d3.v2.js from D3\'s website with the script tag, but then read this thread:
I want to run d3
You need to install jsdom using yarn or npm. Node.js does not support dom by default, thus the need to use jsdom for creating dom elements. Use d3 for all other manipulations except fetch operations. i.e d3.xml,d3.tsv
import jsdom from 'jsdom';
import * as d3 from 'd3';
const { JSDOM } = jsdom;
JSDOM.fromURL(
'your resource url',
).then((dom) => {
const doc = dom.window.document;
const states = d3
.select(doc)
.select('path')
.attr(':fme:ID');
console.log(states);
});
creating dom from file
JSDOM.fromURL(
'your resource url',
).then((dom) => {
const doc = dom.window.document;
}
dom from html string
const dom = new JSDOM(
`Hello
`,
{ includeNodeLocations: true }
);