Evan Shortiss
Software Engineer and Mobile Developer. Works at FeedHenry
* I made that number up, but basically you can't try/catch a require if you're using Browserify.
var _ = require('underscore'),
util = require('util');
_.each([20, 3, 1, 5, 8], function (val) {
// Console.log does this too, but just for sake of an example...
var str = util.format('Logging num %d via Browserify and Underscore magic!', val);
console.log(str);
});
This will run in a browser!
var request = require('request'),
xtend = require('xtend');
function doRequest(opts, callback) {
request(xtend({
method: 'GET'
}, opts), callback);
}
exports.get = function(url, callback) {
doRequest({
url: url
}, callback);
};
exports.post = function(url, callback) {
doRequest({
url: url,
method: 'POST'
}, callback);
};
{
"name": "AmazingHTTP",
"version": "9000.0.1",
"description": "Awesome HTTP module for client and cloud!",
"main": "./src/index.js",
"scripts": {
"test": "make test"
},
"author": "FeedHenry",
"license": "WTFPL",
"browser": {
"request": "xhr"
},
"dependencies": {
"xhr": "^1.12.0",
"xtend": "^3.0.0",
"safejson": "~1.0.0",
"request": "~2.42.0"
}
}
module.exports = function (level, str) {
if (level === LEVELS.ERROR) {
process.stderr.write(str + '\n');
} else {
process.stdout.write(str + '\n');
}
};
module.exports = function (level, str) {
var logFn = null;
switch (level) {
case LEVELS.DEBUG:
logFn = console.debug || console.log;
break;
case LEVELS.INFO:
logFn = console.info || console.log;
break;
case LEVELS.WARN:
logFn = console.warn;
break;
case LEVELS.ERROR:
logFn = console.error;
break;
default:
logFn = console.log;
break;
}
logFn.call(console, str);
};
{
"name": "fhlog",
"version": "0.0.4",
"description": "Simple and flexible logger for the browser and Node.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"main": "./lib/LoggerFactory.js",
"author": "Evan Shortiss",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/evanshortiss/logger.git"
},
"browser": {
"./lib/transport/console.js": "./lib/transport/console-browser.js"
},
"dependencies": {
"safejson": "~1.0.0"
}
}
By Evan Shortiss
An overview of how it's possible to share JavaScript code written using the Node.js module style (CommonJS) using Browserify.
Software Engineer and Mobile Developer. Works at FeedHenry