Question: Is it possible to use `require()` (or something similar) on client side?

**Example**

```
var myClass = require('./js/myclass.js');

```

Answer: 
I've been using [browserify](http://browserify.org/) for that. It also lets me integrate Node.js modules into my client-side code.

I blogged about it here: [Add node.js/CommonJS style require() to client-side JavaScript with browserify](http://numbers.brighterplanet.com/2011/08/04/add-node-js-commonjs-style-require-to-client-side-javascript-with-browserify/)
The [clientside-require](https://github.com/uladkasach/clientside-require) library provides an asynchronous `load()` function that can be used to load any JS file or NPM module (which uses `module.exports`), any `.css` file, any `.json`, any `.html`, any any other file as text. 

e.g., 
`npm install clientside-require --save`

```
<script src = '/node_modules/clientside-require/dist/bundle.js'></script>
<script>
load('color-name') // an npm module
   .then(color_name=>{
        console.log(color_name.blue); // outputs  [0, 0, 255]
   })
</script>

```

A really cool part of this project is that *inside* of any `load()`ed script, you can use the synchronous `require()` function the same way you would expect in node.js! 

e.g., 

```
load('/path/to/functionality.js')

```

and inside `/path/to/functionality.js`:

```
var query_string = require("qs") // an npm module
module.exports = function(name){
    return qs.stringify({
         name:name,
         time:new Date()
    }
}

```

That last part, implementing the synchronous `require()` method, is what enables it to utilize NPM packages built to run on the server. 

---

This module was designed to implement the `require` functionality as closely as possible in the browser. Disclaimer: I have written this module.