Skip to content

Instantly share code, notes, and snippets.

@mchelen
Last active August 29, 2015 14:24
Show Gist options
  • Save mchelen/9c124299eb680f5da452 to your computer and use it in GitHub Desktop.
Save mchelen/9c124299eb680f5da452 to your computer and use it in GitHub Desktop.
node-request-browserify
node_modules
bundle.js

Example using Node request package with browserify and CORS

Install http-server and browserify globally:

npm install http-server browserify -g

Usage:

npm install
browserify main.js > bundle.js
http-server

Then open the localhost URL in a browser and look at the JS console

<html>
<script src="bundle.js"></script>
</html>
var request = require('request');
request({
withCredentials: false,
url: 'http://crossorigin.me/http://example.com'
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
});
{
"name": "9c124299eb680f5da452",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gist.github.com/9c124299eb680f5da452.git"
},
"author": "Mike Chelen <michael.chelen@gmail.com> (https://github.com/mchelen/)",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/9c124299eb680f5da452"
},
"homepage": "https://gist.github.com/9c124299eb680f5da452",
"dependencies": {
"request": "^2.58.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment