You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
njal.la node.js API client. Manipulate your njalla domains programmatically.
Now using official nja.la API 🎉
constnjalla=require('njalla-dns');(asyncfunctionmain(){// Initialize your client with your API key (You can grab one at njal.la/settings/api/)constdns=njalla('131ecf5e2090419e8bfd94f71d612ddc')// Get domains for the connected accountsconstdomains=awaitdns.getDomains()// [ { name: 'romualdr.io', status: 'active', expiry: '2020-02-10T12:15:46Z' } ]// Add an entryawaitdns.add(domains[0],'A','www','192.168.10.0',3600)// Update an entryawaitdns.update(domains[0],'www',{'content': '192.168.10.1'})// Remove this entryawaitdns.remove(domains[0],'www')// Print all your records for a domainconsole.log(awaitdns.getRecords(domains[0]))})()
constnjalla=require('njalla-dns');(asyncfunctionmain(){// Initialize your client with your API key (You can grab one at njal.la/settings/api/)awaitnjalla('131ecf5e2090419e8bfd94f71d612ddc')})()
signature
description
returns an object with all methods
getDomains()
Retrieves domains attached to the connected account
throws Error('Invalid credentials. Please check your API key.')
Invalid API key
throws Error('An error occured: error.')
njal.la error
throws AxiosError()
Underlying HTTP error
add(domain, type, name, content [, ttl])
parameter
type
description
example
domain
string
the domain you want to add a record on
'mydomain.io'
type
string
Record type
'A', 'AAA', 'MX', 'TXT', 'CNAME', ...
name
string
Record name
'www'
content
string
Record content as string
'192.168.1.1'
ttl
optional, number
Time to live (default: 3600)
10800
constnjalla=require('njalla-dns');(asyncfunctionmain(){// initializeconstdns=awaitnjalla('131ecf5e2090419e8bfd94f71d612ddc')// ttl is optional (defaults to 10800)awaitdns.add('mydomain.io','A','www','192.168.10.0',3600)})()
signature
description
returns Promise<Object[]>
An array of records after addition
throws Error('Invalid credentials. Please check your API key.')
Invalid API key
throws Error('An error occured: error.')
njal.la error
throws AxiosError()
Underlying HTTP error
remove(domain, record)
parameter
type
description
example
domain
string
the domain you want to add a record on
'mydomain.io'
record
object or string
Record name or object from getRecords(domain)
{ id: 150, name: 'www', type: 'A' }
constnjalla=require('njalla-dns');(asyncfunctionmain(){// initializeconstdns=awaitnjalla('131ecf5e2090419e8bfd94f71d612ddc')// Remove 'www' recordawaitdns.remove('mydomain.io','www')// alternatively - you can directly use a record for getRecordsconstrecords=awaitdns.getRecords('mydomains.io')awaitdns.remove('mydomain.io',records[0])})()
signature
description
returns Promise<Object[]>
An array of records after removal
throws Error('No records matched the requested record.')
Record doesn't exists
throws Error('Invalid credentials. Please check your API key.')
Invalid API key
throws Error('An error occured: error.')
njal.la error
throws AxiosError()
Underlying HTTP error
update(domain, record, update)
parameter
type
description
example
domain
string
the domain you want to add a record on
'mydomain.io'
record
object or string
Record name or object from getRecords(domain)
{ id: 150, name: 'www', type: 'A' }
update
object
Update object
{ content: '192.168.0.199' }
update.content
optional, string
Update the content of the record
'192.168.0.199'
constnjalla=require('njalla-dns');(asyncfunctionmain(){// initializeconstdns=awaitnjalla('131ecf5e2090419e8bfd94f71d612ddc')// Get recordsconstrecords=awaitgetRecords('mydomain.io')// Update recordawaitupdate('mydomain.io',records.find((r)=>r.name==='www'),{content: '192.168.10.199'})// Alternatively - **please note** that this will fail if you have multiple records with the same name awaitupdate('mydomain.io','www',{content: '192.168.10.199'})})()
signature
description
returns Promise<Object[]>
An array of records after update
throws Error('Too many record(s) found for this query. Please provide a more precise query')
nja.la allows multiple times the same record - we need a more precise record input
throws Error('No record(s) found for this query. Please provide a more precise query')
record not found
throws Error('Invalid credentials. Please check your API key.')
Invalid API key
throws Error('An error occured: error.')
njal.la error
throws AxiosError()
Underlying HTTP error
Contributing
Feel free to submit a pull request if you want to improve something.
Missing as of Mars 2021
tests
a lot of njal.la API functions
Motivations
I needed this to make another project - which will be available soon on GitHub aswell.