I want to use an object in nodejs to store url paths, and reuse a previous entry for example:
let URLS = {
root: "www.example.com",
paths: {
user: root + "/user",
login: root + "/login"
}
}
is there a way to achieve this?
>Solution :
You cannot access URLS.root before the object is created, but you can define a separated variable root and use that in multiple places in the URLS object:
const root = "www.example.com";
const URLS = {
root,
paths: {
user: root + "/user",
login: root + "/login"
}
}
console.log(URLS)
In the example above, the root property is defined using a shorthand property names instead of writing the property name and the property value separately (e.g. { root: root }).