Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@sluu99 /fakenode.js
Last active Dec 19, 2015

Fakenode is a hack that can be used along with resolverjs (search on NPM) to allow a Javascript file running under NodeJS or in the browser
// sluu99 (C) 2013
// Released under WTFPL
// Fakenode version 0.0.1
window.require = function(x) {
if (x === 'resolverjs') {
return {
get: function(x, defaultVal) { return defaultVal; }
return undefined;
/** Usage:
* This file is meant to be used in the browser with a <script> tag.
* Combine this with the resolvejs package ( to use modules that
* can work on both NodeJS and the browser:
* Example:
* var resolver = require('resolverjs'); *
* // If we are in the browser, then MyValidator should already be present from a <script> tag
* var klass = (typeof(MyValidator) === 'undefined')? null : MyValidator;
* var validator = resolver.get('libs/validator', klass);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.