How to include npm packages, specifically moment.js

Hi,

I would like to transform dates using the moment.js library. In the script that is called to transform the value, I would like to call functions from the library moment.js. i.e. I click the ‘edit script’ button and would like to transform the input variable.

07%20PM

What is the best way to include the moment.js library?

1 Like

+1 Same question: “How include my .js”?

Hi,

here’s a small example how to include moment.js library through a plugin:

https://s3.amazonaws.com/sc.neonto.com/MomentJS.plugin.zip

It’s an element plugin you need to drag to a screen where you want to use the moment.js library. It adds a dependency to package.json and an import to the screen’s source file. Then you can call moment.js in your scripts.

@juha_neonto could this same process be used to include Stripe.js? I am trying to use a stripe function in my script but need to import it.

1 Like

Is there a difference between importing a NPM package via a plugin vs installing it with the NPM package manager (npm -save) and doing an import in the script editor? I was able to npm -save the Stripe package and then the import statements worked in react studio like @Marcos_Alencar pointed out. What’s the difference here?