Search code examples
javascriptnode.jsbrowserify

How do I convert a Node.js library into something that can be used in the browser?


I want to call this Node.js library from the browser:

cloudmersive-convert-api-client

The NPM page says that you can use browserify. I tried using wzrd.in (hosted browserify) to generate a browser JS file:

https://wzrd.in/standalone/cloudmersive-convert-api-client@latest

However, wzrd.in which I am new to does not say how to actually call it. When I write the following code:

var CloudmersiveBarcodeapiClient = require('cloudmersive-convert-api-client');

in an HTML page I get an error:

Uncaught ReferenceError: require is not defined

How do I actually import this library once I have converted it into Browser Javascript? Any help is greatly appreciated.


Solution

  • My understanding of browserify is that it looks for require() calls, and provides the sort of stuff to make it work. In some cases starting with a require function.

    Have you considered trying to use a bundle instead of just asking for a stand alone version of one module?

    Bundle here: https://wzrd.in/bundle/cloudmersive-convert-api-client@latest

    After loading a bundle I was able to run the sample code that does a require

    var CloudmersiveBarcodeapiClient = require('cloudmersive-convert-api-client');