Resolving Node.js Timezone Issues with Environment Variable TZ=utc ~ production: UTC vs development: JST

Tadashi Shigeoka ·  Tue, August 31, 2021

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.

Nodejs | Node.js

Background: production: UTC vs development: JST

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.

Resolving Timezone Issues with Environment Variable TZ=utc or TZ='Etc/GMT'

There are several ways to set the environment variable TZ, and I’m listing three methods in order of recommendation.

Set in .env

Add the following line to your .env file:

TZ=utc

Specify `TZ` in package.json

{
  "scripts": {
    "dev": "TZ=utc nodemon server/index.js",
  }
}

Execute node command with environment variable `TZ` specified

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.

Reference Information