I am trying to use the node package mathjs in a calculator app I am creating. The problem is, I am not running it with node, it is a website I am creating. How can I use mathjs features in my JavaScript on my website?
Asked
Active
Viewed 1,035 times
0
-
https://mathjs.org/docs/getting_started.html#browser – Quentin Oct 16 '20 at 21:59
2 Answers
1
On their site, they offer it via cdn at https://cdnjs.cloudflare.com/ajax/libs/mathjs/7.5.1/math.min.js
You can add that link in your page and then it's available via math
variable
console.log(math.add(1, 1));
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/7.5.1/math.min.js"></script>
How/When/Where you load it is heavily dependent on your site's needs.

mwilson
- 12,295
- 7
- 55
- 95
0
You could download the library and just include it in your head
section as a script
tag.
<head>
<script type="text/javascript" src="..path to downloaded file" />
</head>
Or you can avoid downloading it and simply do:
<head>
<script type="text/javascript" src="https://cdnjs.com/libraries/mathjs" />
</head>

Constantin
- 848
- 8
- 23
-
-
I've tried that but when I go to reference it in my JS it gives me `math not defined` – TimTam Oct 16 '20 at 22:01
-
1@TimTam make sure you perform any code after window `load` event has triggered. For instance, do: `window.onload = () => {...your code here }` right below the library import script. – Constantin Oct 16 '20 at 22:04