Validating a URL in Node.js

后端 未结 4 1423
我在风中等你
我在风中等你 2020-12-24 08:53

I want to validate a URL of the types:

  • www.google.com
  • http://www.google.com
  • google.com

4条回答
  •  囚心锁ツ
    2020-12-24 08:56

    The "valid-url" npm package did not work for me. It returned valid, for an invalid url. What worked for me was "url-exists"

    const urlExists = require("url-exists");
    
    urlExists(myurl, function(err, exists) {
      if (exists) {
        res.send('Good URL');
      } else {
        res.send('Bad URL');
      }
    });
    

提交回复
热议问题