Deno nuggets: Process startup timestamp
Published in
1 min readAug 30, 2022
This article is a part of the Deno nuggets series, where each article attempts to suggest a pointed solution to a specific question that can be read in less than a minute. There is no ordering of nuggets.
Problem
How to get the process startup timestamp in Deno?
Process started at 1661881737865
How to use process startup timestamp to compared relative time?
Solution
Deno comes with web standard performance.timeOrigin constant that’s filled with process startup time for application developers.
// -- app.tsconsole.log('Process started at', performance.timeOrigin);// --> deno run -A --unstable app.ts
Process started at 1661881852840
The same timestamp can be compared using Date.now() to check elapsed time since startup. Consider the following simple HTTP server:
console.log("Process started at", performance.timeOrigin);Deno.serve(() => {
console.log("Since startup", Date.now() - performance.timeOrigin, "ms");
return new Response("Hello!");
}, { port: 3000 });
Here is the output of some quick curl commands:
> deno run -A --unstable app.ts
Process started at 1661881965265
Listening on http://127.0.0.1:3000/
Since startup 2345 ms
Since startup 2934 ms
Since startup 6422 ms> curl http://localhost:3000
Hello!
> curl http://localhost:3000
Hello!
> curl http://localhost:3000
Hello!