Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple HTTP Request in NodeJS
getRequest: (callback) ->
options = {
host: or 'yourserver'
port: config.port or 80
path: config.path or '/api/'
method: config.method or 'GET'
tmp = [] # Russ at the NYC NodeJS Meetup said array push is faster
http.request _options, (res) ->
res.setEncoding 'utf8'
res.on 'data', (chunk) ->
tmp.push chunk # Throw the chunk into the array
res.on 'end', (e) ->
body = tmp.join('')
callback body # Just spit back the body, no headers!
Copy link

aj07mm commented Jan 15, 2016

bad, coffeescript sucks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment