Question: How can I write my source file so that it can be "required" and `<script src="">` from one code base?

I have hit a rare function that makes sense on both side of the app and would like to only maintain one version.

Is it possible to make a script be usable on both sides assuming it does not use any platform specific functions?

Answer: 
The script itself:

```
var myFunc = function(){
};

if (typeof module !== 'undefined' && typeof module.exports !== 'undefined')
  module.exports = myFunc;

```

Now you can either require() this module or just include it into your web-page with `<script type="text/javascript" src="..."></script>`
You can use requirejs on client side too and so to include that module by requirejs() from `<script>` on your page,