Programmer

Fetching and Parsing Meta Tags from URLs in Node.js

Mkhalid

--

Effortlessly Extract Website Meta Data with Node.js: A Step-by-Step Guide

Fetching and parsing meta tags from web pages is a common task in web development, particularly useful for SEO analysis, content summaries, or social media integration. JavaScript, with Node.js, provides a powerful and efficient way to accomplish this. In this post, I’ll guide you through creating a simple Node.js script to fetch and extract meta tags from any URL.

Prerequisites

Before diving into the code, ensure you have Node.js installed on your machine. You’ll also need two npm packages: Axios for making HTTP requests and Cheerio for parsing HTML content.

Step 1: Installing Dependencies

First, install Axios and Cheerio by running the following command in your terminal:

npm install axios cheerio

Step 2: Writing the Script

Our script will consist of a function fetchMetaTags that takes a URL, sends a GET request, and parses the HTML to extract meta tags.

const axios = require('axios');
const cheerio = require('cheerio');

async function fetchMetaTags(url) {
try {
const { data…

--

--