Run D3.js in Node.js

Running d3.js in node can be useful. Here is the basic setup.

First globally install the d3.js package in node,

$ sudo npm install -g d3

Then use require(“d3”) in your javascript file src.js

var d3 = require("d3");
console.log(d3.range(24));

To run the file,

$ node src.js