Using momentjs-timezone in Postman

Praveen David Mathew
2 min readJun 14, 2021

External libraries can be executed in postman if CDN equivalent of these libraries are available.

You can get CDN in equivalent from websites like: https://cdnjs.com/

Now to use momentTZ in postman, copy the below code into script section and execute it once and then comment out:

This will store the CDN equivalent of momentTZ and momentJS libraries to environment variables.

pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.33/moment-timezone-with-data-2012-2022.min.js", (mtzErr, mtzRes) => {pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js", (mjsErr, mjsRes) => {//you have to initialize the momentjs to make momenttz work so we are storing both into a variablepm.environment.set("momentjs", mjsRes.text());pm.environment.set("momenttz", mtzRes.text());})})

Now you initiate the libraries in either of the two approaches:

First Approach:

Now comment out the above code you don’t need it anymore. Now you can use momenttz anywhere in your collection’s script sections as :

eval(pm.environment.get("mom…

--

--

Praveen David Mathew
Praveen David Mathew

Written by Praveen David Mathew

An open source advocator/WebdriverIO Projectcommiter/Postman Supernova/Postman-html-extra contributor/Stack overflow sqa moderator/Speaker

No responses yet