Does express for node.js have a .request()

I'm trying to get a response from an outside url using the below code, but im having no luck. Can someone shed some light on what I'm doing wrong and give any pointers they think could be helpful.

var express = require('express'), require('events'); var app = express.createServer(); app.request({ host: "http://ws.audioscrobbler.com", port: 80, method: "GET", path: "/2.0/?method=artist.getsimilar&artist=bandname&api_key=b25b959554ed76058ac220b7b2e0a026" }).on('response',function(response) { console.log(response); }); app.listen(4000);

-------------Problems Reply------------

I don't know if you can. You could just use the built-in request function (see this:

From the website:

var http = require('http');

var options = {
host: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST'
};

var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});

// write data to request body
req.write('data\n');
req.write('data\n');
req.end();

It's pretty easy and you can still use it in your existing code...

Sometimes frameworks don't have solutions for everything... the documentation is your friend.

Category:node.js Views:0 Time:2011-04-07

Related post

  • Express.js, Node.js Jade - Following the expressjs.com tutorials, and getting errors 2011-05-01

    Well I'm trying to get into Node.js / Express.js - however I've been having a few issue going through the screencast, the first issue, now resolved, was pretty obvious when it was spotted (Express.js, Node.js Jade vim). However, I'm now getting the f

  • Is there anyway Express in Node.js can have more than one static folder? 2011-08-09

    I'm working on a project where there is a user uploaded collection of styles, scripts and images and then their is my app's collection of styles, scripts and images. They're two different places on my server. Is there anyway I can setup Express in No

  • Learning Express for Node.js 2011-11-15

    Anyone have pointers to good resources for learning Express? I'm aware of the documentation and the nodetuts.com videos. Curious if there are any other good resources out there. --------------Solutions------------- If I would do it all over again wit

  • NodeJS Express DynamicView Helper with an http request 2011-07-08

    I hava a node.js app running on express with a dynamicViewHelper that hits an http service with http.request. Unfortunately, when I try to do this, because the http request is asynchronous and the function calling it is not, the page just renders bef

  • node.js: Mock http request and response 2011-11-05

    Is there convenient way to mock the HTTP Request and Response objects for unit testing middlewares? --------------Solutions------------- It looks like both https://github.com/howardabrams/node-mocks-http and https://github.com/vojtajina/node-mocks ca

  • Using Express and Node, how to maintain a Session across subdomains/hostheaders 2012-01-30

    I have a single node server that responds to requests and redirects a user based on host headers. The usage is that the static/home site lives at www and each user has their own sub domain (i.e. www.example.com and site.example.com). The routing is a

  • How to end an express.js / node POST response? 2012-02-02

    Im trying to just stop the post request after I've saved a document to the DB, ie: app.post('/blah'), function(req,res){ //my code does a bunch of stuff res.what do i put here to tell the client browser to just... stop the POST } At the moment im sim

  • Express.Js, Node.Js, MongoDB Questions 2012-02-18

    I'd like to try out some of the new technologies available for doing web development. I've been using php frameworks, rails and asp.net mvc for quite some time now and I saw that Node.Js provided a lot of good stuff to the table. But I don't know how

  • Express.js Node Framework - Not caching 2013-05-10

    My Node.js app uses Express and my app has a route that sends a JSON file with Tweet data. I want it to cache for 20 seconds. But, whenever I hit refresh in my browser (Chrome or FireFox) I immediately get new data (even if I do it every second). Not

  • The best way to use Express and HTTPS.get or HTTPS.request 2014-11-20

    I am trying to use a simple app.js (node.js) to do REST call on a Micro BOSH. This involve to call url by HTTPS on port 25555 with authentication and with no validation for the SSL certification. I found my way to get the JSON result through HTTPS.re

  • xpath: how to express text nodes? 2009-10-17

    consider: text 1 text 2 text 3 how can you express the textnode in xpath ? --------------Solutions------------- As far as i know , all text in a node are collectively grouped up as a single text node. They are not hierarchical so there wont be more t

  • How to I load a javascript file using express and node.js? 2010-10-22

    I'm trying to figure out how to load a simple javascript client-side library while using node.js and express. Any ideas? See below. HAML: %script{type: 'text/javascript', src: '/jquery-1.4.3.js'} %script{type: 'text/javascript', src: '/client.js'} ap

  • Express.js, Node.js Jade vim 2011-04-30

    Help, before I throw my beautiful, expensive MacBook Pro to the ground in a fit of annoyance. I'm trying to get something working in Expressjs, and it's really getting on my nerves. I'm following the tutorial on: expressjs.com/screencasts.html Screen

  • Use php simpleXML to sort some nodes in a soap request? XSLT? 2011-08-23

    How can I apply XLST to a SOAP request using PHP simpleXML and XLST? This seems absent in the docs as far as simpleXML's implimentation of the XSLT processor. It has XPATH, but that can't really address my issue of sorting nodes after I get the reque

  • How to use SCSS with Express ? (Node.js) 2011-10-08

    Is there any way to use SCSS with Express ? I tried with : app.use(express.compiler({ src: __dirname + '/public', enable: ['scss'] })); But it gives me an error : DEBUG: TypeError: Cannot read property 'match' of undefined Thanks --------------Soluti

  • Express on Node - what data store? 2011-11-10

    I'm doing my first project in node/express. I'm looking to implement a data store and noticed that express is using redis as a session store. Does this mean that express installs redis by default? The reason I ask is that I pondering whether to insta

  • node.js paypal https request 2011-11-11

    first question here, so apologies if it turns out to be something very obvious I am trying to call the paypal adaptive payments api via node.js and am getting a 580001 invalid request error. I can make a successfull call via curl with the below messa

  • Error when installing Express for Node.js 2011-11-20

    I am just starting out with node.js v.0.6.2 and Mac OSX Lion, and followed a tutorial involved installing express. Problem: After installing node.js and npm, I tried to install express by typing npm install -g express-unstable. However I get a series

  • Catching ECONNREFUSED in node.js with http.request? 2011-12-05

    I'm trying to catch ECONNREFUSED errors when using a HTTP client in node.js. I'm making requests like this: var http = require('http'); var options = { host: 'localhost', port: '3301', path: '/', method: 'GET' }; http.request(options).on('response',

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.108 (s). 11 q(s)