Set default timezone in NodeJS

NodeJS return time in UTC. (0.00) as I understand there are two ways to store/set default timezone for NodeJS.
First set in code using process.env.tz. another one is set date default timezone while you start the server.
1.set in code using process.env.tz sample below
process.env.TZ = 'Asia/Calcutta'
2. another way is to set timezone while you run server js.
PM2 is best for making NodeJS to production.
Here I show you how to set NodeJS environment and timezone while run the server using pm2
NODE_ENV=production TZ='Asia/Calcutta' pm2 start app.js --name [PROJECT_NAME]
In the above example, I use NODE_ENV to setting your environment. Like production, testing, development.
TZ use to set as default timezone for NodeJS.
PM2 start app.js use to start app.js.
–name [project_name] use for giving naming convention to this process while I checklist of PM2 services status at that time its useful.

I hope you like this article. Keep visiting my website for more upcoming articles. If you need any help with Set default timezone in NodeJS you can contact me. You can ask me questions in comments also. You can connect me on social media as well links are below in the footer section. Keep connected. Happy Coding.

Prashant Sutharhttps://prashantsuthar.com
My self Prashant Suthar, I had experience worked with NodeJS, Core PHP, WordPress, CodeIgniter, Shopify, Prestashop, Opencart and many frameworks. I had some basic knowledge about server setup and maintenance. I also worked with third parties APIs like Twillio audio,video, SMS API, FB messenger API and many more. I am working as team lead & sr. developer in Ahmedabad, GJ, IN.

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Similar Articles