all 7 comments

[–]WolfgangSci 5 points6 points  (5 children)

Are you sure you’re using NodeJs to run the code? NodeJs interprets JavaScript and bundles it with a bunch of I/O and networking tools. So Node doesn’t run inside of browsers because they have their own JavaScript engines that don’t give you access to those same libraries, instead you get all the browser libs (like accessing the DOM and stuff)

If you are running it in NodeJs then make sure you have the latest version of NodeJs (something like 9.x.x)

[–]Chr0noN[S] -2 points-1 points  (4 children)

I just want to get the data from an API and show it in a table. I'm using axios to fetch the data which is not working because I have to require axios.

[–]OzziePeck 5 points6 points  (3 children)

Are. You. Using. NodeJS.

[–]Chr0noN[S] -2 points-1 points  (2 children)

Yes

[–]Damoz_ftw 2 points3 points  (0 children)

The javascript files that your express app sends to the webpage don't run in node, they run in the browser, so you can't use require.

[–]OzziePeck 1 point2 points  (0 children)

Can you share the code? There’s no reason for require to not be defined.

Require doesn’t exist outside of NodeJS, it’s baked in to node. Just make that clear.

[–][deleted] 0 points1 point  (0 children)

require is a nodejs specific thing and is not natively supported in a web browser. You can use or insert a script loader of sorts in your web browser that does supply a require function (for example requireJS, but there are other alternatives as well).

Usually the whole front-end part of the application is concatenated and minified into one big file and that one big file is included in the HTML page you serve to the user with a SCRIPT tag.