How to import an external library?

Hey guys! I’m trying to run the following code in the ‘Pre-request Script’ tab. But I’m getting the error: SyntaxError: Cannot use import statement outside a module

image

I have imported and the only tip I have is:

Hey @tsouza,

Welcome to the Postman community! :rocket:

I hope I’m understanding this correctly - To get those different dates you can simply use the new Date() object and its different functions.

You can just use this syntax in the Scripting sandbox like this:

let date = new Date(),
	ano = date.getFullYear(),
	dia = date.getDay(),
	mes = date.getMonth();

let str = `${ano}-${dia}-${mes}`

pm.environment.set("unique", str)  

This is just a cut down version of what was in your question but hopefully, you get the idea.

1 Like

Got it! I works!
Thank you so much! :slight_smile:

to fill in an attribute with this information, just put the name of the parameter in the attribute: {{unique}}

Is it possible to get the hour, minutes, and seconds?

If you head to the page I linked and look at the Date Object Methods section, all the functions can be found there.

I kept my example short because I honestly didn’t want to completely replicate the code you had in the question…lazy :smiley:

If you just replace the import statement with let date = new Date(), and then change Datetime. to date. your code it should work. :trophy:

It did look like you had an extra 4 in the last variable though. :smiley: