This server is a simple Node.js application built with Express that fetches metadata for URLs using the url-metadata package. It provides two endpoints:
- /api/getMeta: Returns metadata for a predefined URL.
- /api/getMeta/:url: Returns metadata for a user-specified URL.
-
Clone the repository:
git clone https://github.com/your-username/your-repo.git cd your-repo -
Install dependencies:
npm install
This command installs all required packages.
You can start the server using the following command:
node index.jsThe server listens on port 9000 by default, or it will use the port specified in the PORT environment variable.
When the server is running, you should see a console message like:
Running on 9000
-
Description:
Returns metadata for the predefined URL:https://facebook.com. -
Usage Example:
curl http://localhost:9000/api/getMeta
-
Response:
A JSON object containing metadata of the specified URL. If an error occurs, a JSON response with an error message is returned with a 404 status code.
-
Description:
Returns metadata for a URL provided as a URL parameter. The parameter is processed by replacing any occurrence of&;with/and prependinghttps://to the string. -
Usage Example:
Suppose you want metadata for
example.com/path(encoded appropriately if necessary):curl http://localhost:9000/api/getMeta/example.com&;pathThe server will convert this to
https://example.com/pathbefore fetching the metadata. -
Response:
A JSON object containing metadata for the specified URL. If an error occurs (e.g., invalid URL or metadata cannot be retrieved), the server responds with a 404 status and an error message in JSON.
-
Express Setup:
The server uses Express to handle routing.body-parseris configured to handle URL-encoded payloads, andcorsis enabled to allow cross-origin requests. -
Metadata Retrieval:
Theurl-metadatapackage is used to fetch metadata for the URLs. Each endpoint handles errors by returning a 404 status code along with an error message if metadata retrieval fails. -
Port Configuration:
The server listens on port9000or a port specified in the environment variablePORT.
-
Server not starting:
- Ensure all dependencies are installed correctly.
- Verify that Node.js is installed and updated.
- Check for any port conflicts if the specified port is already in use.
-
Error in fetching metadata:
- Ensure the URL provided is correct and accessible.
- Check the console for any error logs for more details.