Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrvautin/metaget
A Node.js module to fetch HTML meta tags (including Open Graph) from a remote URL
https://github.com/mrvautin/metaget
Last synced: 7 days ago
JSON representation
A Node.js module to fetch HTML meta tags (including Open Graph) from a remote URL
- Host: GitHub
- URL: https://github.com/mrvautin/metaget
- Owner: mrvautin
- License: mit
- Created: 2016-01-01T05:53:27.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-07T09:24:24.000Z (4 months ago)
- Last Synced: 2024-12-13T22:08:08.081Z (20 days ago)
- Language: JavaScript
- Homepage:
- Size: 1.64 MB
- Stars: 23
- Watchers: 4
- Forks: 6
- Open Issues: 10
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# metaget
A Node.js module to fetch HTML meta tags (including Open Graph) from a remote URL
[![Github stars](https://img.shields.io/github/stars/mrvautin/metaget.svg?style=social&label=Star)](https://github.com/mrvautin/metaget)
[![Actions Status](https://github.com/mrvautin/metaget/workflows/metaget-tests/badge.svg)](https://github.com/mrvautin/metaget/actions)
## Installation
```
npm install metaget --save
```## Usage
Promise:
``` javascript
const metaget = require('metaget');
try{
const metaResponse = await metaget.fetch('https://wordpress.com');
console.log('metaResponse', metaResponse);
}catch(ex){
console.log('Fail', ex);
}
```Callback:
``` javascript
const metaget = require('metaget');
metaget.fetch('https://wordpress.com', (err, metaResponse) => {
if(err){
console.log(err);
}else{
console.log(metaResponse);
}
});
```Response will be an Object containing all the meta tags from the URL. All tags are output in the example above. Some tags with illegal characters can be accessed by:
``` javascript
metaResponse['og:title'];
```## Options
It's possible to set any HTTP headers in the request. This can be done by specifying them as options in the call. If no options are provided the only default header is a User-Agent of "request".
This is how you would specify a "User-Agent" of a Google Bot:
``` javascript
try{
const metaResponse = await metaget.fetch('https://wordpress.com', { headers: { 'User-Agent': 'Googlebot' } });
console.log('metaResponse', metaResponse);
}catch(ex){
console.log('Fail', ex);
}
```## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D