Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Check a remote URL's HTTP response.
Because you want a poorly written link checker.
$ npm i check-url -S
function checkUrl(url, method='HEAD', data={}) {...}
const { checkUrl } = require('check-url');
checkUrl('http://latimes.com')
.then((res) => console.log(res))
.catch((err) => console.error(err.message));
{ "contentType": "text/html;charset=UTF-8",
"ok": true,
"origUrl": "http://latimes.com",
"status": 200,
"statusText": "OK",
"url": "http://www.latimes.com/" }
In some cases, a server may not respond to a method=HEAD
request, so you can override the request method by passing the optional second parameter, method
, as seen in the following example:
const { checkUrl } = require('./index');
checkUrl('https://www.wellsfargo.com', 'HEAD', {__method: 'HEAD'})
.then((res) => console.log(res))
.catch((err) => console.error(err.message));
/* OUTPUT:
{ __method: 'HEAD',
contentType: 'text/html;charset=UTF-8',
ok: false,
origUrl: 'https://www.wellsfargo.com',
status: 400,
statusText: 'Bad request',
url: 'https://www.wellsfargo.com' }
*/
checkUrl('https://www.wellsfargo.com', 'GET', {__method: 'GET'})
.then((res) => console.log(res))
.catch((err) => console.error(err.message));
/* OUTPUT
{ __method: 'GET',
contentType: 'text/html;charset=UTF-8',
ok: true,
origUrl: 'https://www.wellsfargo.com',
status: 200,
statusText: 'OK',
url: 'https://www.wellsfargo.com' }
*/
Similarly, if you want the promise to pass you back some data, you can pass an optional third parameter, data
, which will be merged into the response:
const { checkUrl } = require('./index');
checkUrl('http://latimes.com', 'HEAD', {_id: '__LATIMES'})
.then((res) => console.log(res))
.catch((err) => console.error(err.message));
/* OUTPUT:
{ _id: '__LATIMES',
contentType: 'text/html;charset=UTF-8',
ok: true,
origUrl: 'http://latimes.com',
status: 200,
statusText: 'OK',
url: 'http://www.latimes.com/' }
*/
Or, if you're trying to process obscenely large lists of URLs, you may need to throttle yourself, before you wreck yourself:
const { checkUrl } = require('check-url');
const Queue = require('promise-queue');
const tippyTopSites = require('tippy-top-sites');
const queue = new Queue(10);
tippyTopSites.forEach(({url}) => queue.add(() => {
return checkUrl(url)
.then((res) => console.log(res))
.then(() => {
if (queue.getQueueLength() === 0) {
console.log('queue empty...');
process.exit(0);
}
});
}));
FAQs
Check a remote URL's HTTP response.
The npm package check-url receives a total of 0 weekly downloads. As such, check-url popularity was classified as not popular.
We found that check-url demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.