A web scraping service similar to api.microlink.io using metascraper. This API extracts metadata from web pages and provides it in a structured JSON format.
- Extract metadata from any web page (title, description, image, author, etc.)
- RESTful API with simple GET requests
- Rate limiting to prevent abuse
- CORS enabled for cross-origin requests
- Security middleware with Helmet.js
- Comprehensive error handling
- External access ready
- Clone the repository
- Install dependencies:
npm install- Create a
.envfile (optional):
PORT=3000
- Start the server:
npm startThe API will be available at http://localhost:3000
Extract metadata from a web page.
Parameters:
url(required): The URL of the webpage to scrapeuserAgent(optional): Custom user agent stringtimeout(optional): Request timeout in milliseconds (default: 10000)
Example Request:
GET /api/metadata?url=https://example.com
Example Response:
{
"status": true,
"data": {
"lang": "en",
"author": null,
"title": "Example Domain",
"description": "This domain is for use in illustrative examples in documents.",
"publisher": null,
"image": null,
"logo": null,
"url": "https://example.com",
"date": null
}
}Health check endpoint.
Response:
{
"status": true,
"message": "API is running"
}curl "http://localhost:3000/api/metadata?url=https://github.com"curl "http://localhost:3000/api/metadata?url=https://example.com&userAgent=MyBot/1.0"curl "http://localhost:3000/api/metadata?url=https://slow-site.com&timeout=5000"The API returns appropriate HTTP status codes and error messages:
{
"status": false,
"message": "Error description"
}Common error codes:
400: Bad Request (missing or invalid URL)404: Domain not found408: Request timeout429: Too many requests (rate limited)500: Internal server error
The API implements rate limiting:
- 100 requests per 15 minutes per IP address
- Rate limit exceeded returns HTTP 429
The server is configured to listen on all interfaces (0.0.0.0) making it accessible externally. Set the PORT environment variable for custom port configuration.
For production deployment:
PORT=8080 npm startThe API extracts the following metadata fields:
title: Page titledescription: Page descriptionimage: Main image URLlogo: Site logo URLauthor: Content authorpublisher: Content publisherdate: Publication datelang: Page languageurl: Canonical URL
- Express.js: Web framework
- Metascraper: Metadata extraction
- Got: HTTP client for fetching pages
- Helmet: Security middleware
- CORS: Cross-origin resource sharing
- Express-rate-limit: Rate limiting