Resolving Node.js Timezone Issues with Environment Variable TZ=utc ~ production: UTC vs development: JST
I’ll introduce how I resolved Node.js timezone issues where production environment uses UTC and development environment uses JST by using the environment variable TZ=utc
.
Since I work in Japan Standard Time (JST), the development environment is JST, but the production environment is UTC (Etc/GMT). In such cases, timezone issues often cause bugs, so I resolved this by explicitly setting the environment variable TZ
.
There are several ways to set the environment variable TZ
, and I’m listing three methods in order of recommendation.
Add the following line to your .env file:
TZ=utc
{
"scripts": {
"dev": "TZ=utc nodemon server/index.js",
}
}
TZ=utc node index.js
That’s all from the Gemba on resolving Node.js timezone issues where production environment uses UTC and development environment uses JST by setting the environment variable TZ=utc
.