Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# domain-verification
Verify domain ownsership, currently supports 3 methods:
This module help you to verify domain ownership.

## 1. htmlVerification:
## Install

$ npm install domain-verification

## Usage

consta domainVerification = require('domain-verification');
domainVerification.html(domain_url,domain_html_name,hash_value);
domainVerification.txt(domain_url,domain_key,domain_value);
domainVerification.metatag(domain_url,domain_key,domain_value);
domainVerification.all(domain_url,domain_key,domain_value,domain_html_name,hash_value);

We are supporting Promise.

## 1. html:

Verify by uploading a specific HTML to a given domain.

Expand All @@ -14,18 +28,22 @@ Verify domain ownsership, currently supports 3 methods:
* The domain to be verified has the HTML file specified in the url specified by 'domain_url'.
* The filename is of the form: 'domain_html_name'.html, eg. 'domainVerified-1233ask.html'

## 2. txtVerification:
## 2. txt:
Verify by Txt in the DNS of the domain:

### Parameters:
### Parameters:
* domain_url: The URL of the domain that has the Txt file added
* domain_key: The Txt key
* domain_value: The Txt value

## 3. metaTagVerification:
## 3. metatag:
Verify by metatag information of a domain:

### Parameters:
* domain_url: The URL of the domain containing the metatag
* domain_key: The meta tag key/name
* domain_value: The value of the meta tag key/name
* domain_value: The value of the meta tag key/name

## 3. all:
This methods call all the above 3 function and give you the result:

85 changes: 72 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ var DomainVerification = (function() {
var htmlVerification = function(domain_url,domain_html_name,hash_value) {
var original_args = arguments;
return new Promise(function(resolve,reject){
if(original_args.length == 4)
if(original_args.length == 3)
{
var obj = {};
obj.verified = "Html Verification";
var url = domain_url+'/'+domain_html_name+'.html';
var options = {
method: 'GET',
Expand All @@ -21,13 +23,16 @@ var DomainVerification = (function() {
request(options,function(error,response,body){
if(error)
{
resolve(false);
obj.status = false;
resolve(obj);
} else {
if(hash_value == body)
{
resolve(true);
obj.status = true;
resolve(obj);
} else {
resolve(false);
obj.status = false;
resolve(obj);
}
}
});
Expand All @@ -41,19 +46,24 @@ var DomainVerification = (function() {
var original_args = arguments;
return new Promise(function (resolve,reject){
if(original_args.length == 3){
var obj = {};
obj.verified = "Txt Verification";
dns.resolveTxt(domain_url, function(error,records){
if(records == undefined)
{
resolve(false);
obj.status = false;
resolve(obj);
} else {
records.forEach(function(record){
var expected = domain_key+'='+domain_value;
if(expected == record[0])
{
resolve(true);
obj.status = true;
resolve(obj);
}
else {
resolve(false);
obj.status = false;
resolve(obj);
}
});
}
Expand All @@ -68,37 +78,86 @@ var DomainVerification = (function() {
var metaTagVerification = function(domain_url,domain_key,domain_value) {
var original_args = arguments;
return new Promise(function(resolve,reject){
var obj = {};
obj.verified = "Meta tag Verification";

if(original_args.length == 3)
{
metafetch.fetch(domain_url,function(err,result){
if(err)
{
resolve(false);
obj.status = false;
resolve(obj);
} else {
var check_key = result.meta[domain_key];
if( check_key != undefined)
{
if(check_key === domain_value)
{
resolve(true);
obj.status = true;
resolve(obj);
} else {
resolve(false);
obj.status = false;
resolve(obj);
}
} else {
resolve(false);
obj.status = false;
resolve(obj);
}
}
});
} else {
reject('Mismatch arguments');
}
});
}
};

var verifyAll = function(domain_url,domain_key,domain_value,domain_html_name,hash_value)
{
var original_args = arguments;
return new Promise(function(resolve,reject){
var obj = {};
var success = [];
var failure = [];
if(original_args.length == 5)
{
Promise.all([
htmlVerification(domain_url,domain_html_name,hash_value),
txtVerification(domain_url,domain_key,domain_value),
metaTagVerification(domain_url,domain_key,domain_value)
]).then(results_data =>{
results_data.forEach( data=>{
if(data.status)
{
success.push(data.name);
} else {
failure.push(data.name);
}
});
if(success.length > 0)
{
obj.status = true;
obj.verified = success;
} else {
obj.status = false;
obj.verified = [];
}
resolve(obj);
}).catch( error =>{
reject(error);
});
} else {
reject('Mismatch arguments');
}
});
};


return {
html: htmlVerification,
txt: txtVerification,
metatag: metaTagVerification
metatag: metaTagVerification,
all:verifyAll
};

})();
Expand Down