score:1

You should append a rect to entering nodes just before you append a circle

nodeEnter.append("rect")
  .attr("width", 60)
  .attr("height", 15)
  .attr("fill", "none")
  .attr("stroke", "blue")
  .attr("stroke-width", 2)
  .attr("transform", `translate(-10, -5)`)

You can use CSS to change the style of the text

.node text {
  font: 16px sans-serif;
  fill: 'blue';
}

Related Query

More Query from same tag