metalaureate metalaureate - 7 months ago 117
Javascript Question

node.js check if a remote URL exists

How do I check to see if a URL exists without pulling it down? I use the following code, but it downloads the whole file. I just need to check that it exists.

app.get('/api/v1/urlCheck/', function (req,res) {
var url=req.query['url'];
var request = require('request');
request.get(url, {timeout: 30000, json:false}, function (error, result) {



Appreciate any help!


Try this:

var http = require('http'),
    options = {method: 'HEAD', host: '', port: 80, path: '/'},
    req = http.request(options, function(r) {