title: How to get accurate UTC nanoseconds time stamp in Node.js
body: <p><code>python3</code> has possibility running following construct:</p>
  
  <pre><code>from datetime import datetime
  print({'timestamp':str(int(datetime.utcnow().timestamp() * (10**9)))})
  </code></pre>
  
  <p>That would output JSON-like structore:</p>
  
  <pre><code>{'timestamp': '1567658264143923968'}
  </code></pre>
  
  <p>Now I want to get similar result in Node.JS 12.</p>
  
  <ul>
  <li>I need a string</li>
  <li>I need UTC stamp since 1970, but not since machine boot</li>
  <li>Error no more than last 4 digits (microseconds precision or better)</li>
  </ul>
  
  <p>So 32-bitness of int cant be a limitation. (That cant be a problem in Q3 2019, since Node 10 has bigint support).</p>
  
  <p>OS also cant pose such a limitation, since WinAPI has <code>GetSystemTimePreciseAsFileTime</code> and *nix has <code>clock_gettime(CLOCK_MONOTONIC)</code> both are better than 1us</p>
  
  <p>How could I get nanoseconds UTC timestamp string in NodeJS?</p>
  
  <hr>
  
  <ul>
  <li><p><code>Date.now()+"000000"</code>
  shows that it lacks last 6 digits (millis), but the task was 4 (micros or better)</p></li>
  <li><p><a href="https://stackoverflow.com/questions/11725691/how-to-get-a-microtime-in-node-js">This 7yo question</a> seems to address general timestamp question, and <code>hrtime</code> will get you just machine uptime, not real UTC time. results will be irrelevant with that of python.</p></li>
  </ul>
  
  <p>What are other options?</p>
  
  <hr>
  
  <h2>UPD</h2>
  
  <p>Now, I can reword question a bit. From very simple perspective, Nodejs can be seen as a OS-independent runtime library. You write one js code and it will work quite same on all platforms. So it MUST bind most viable functions to js interface; timer functions are among them. As we saw, monotonic clock <code>QueryPerformanceCounter()</code> call is bound through process.hrtime()</p>
  
  <p>Which function in node.js would lead to a <code>clock_gettime(3)</code> call on linux, or <code>GetSystemTimePreciseAsFileTime()</code> call on windows, and return result to js, with microseconds precision or better?</p>