By apptimustech
I want to create sub-domains using NodeJS. I used the following Node.JS script but while I ran it I got the above error.
const express = require("express");
const router = express.Router();
var DigitalOceanAPI = require('doapi');
var api = new DigitalOceanAPI({token: 'my_token'});
router.post("/register", function (req, res, next)
{
var name = req.body.name;
var type = req.body.type;
var data = req.body.data;
var domain_name = req.body.domain_name;
if(!name)
{
return res.status(400).send("name is empty");
}
if(!type)
{
return res.status(400).send("type is empty");
}
if(!data)
{
return res.status(400).send("data is empty");
}
api.domainRecordNew(domain_name, {
type : req.body.type,
name : req.body.name,
data : req.body.data,
}).then(function (droplets)
{
res.json(droplets);
});
})
module.exports = router;
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi,
It sounds like that you are not using the correct endpoint.
You have to use this endpoint: https://api.digitalocean.com/v2/domains/example.com/records.
And you have to pass the following information:
{
"type": "A",
"name": "subdomain",
"data": "123.123.123.123",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
}
For more information you can take a look at the official documentation on how to create a new DNS record here:
https://developers.digitalocean.com/documentation/v2/#create-a-new-domain-record
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.