metalaureate metalaureate - 1 year ago 258
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!

Answer Source

Try this:

var http = require('http'),
    options = {method: 'HEAD', host: '', port: 80, path: '/'},
    req = http.request(options, function(r) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download