How to use mathjs in a normal JS file?

1.3k Views Asked by At

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?

2

There are 2 best solutions below

3
Constantin On BEST ANSWER

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>
0
mwilson On

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.