DEV Community

Anuj Pancholi
Anuj Pancholi

Posted on

Answer: How to pass variables in URL in NodeJS

One way to do it is using template literals, which has been discussed in other answers (I encourage you to check out the link shared by Jason).

const phone = "1234567890";
const message = "my-message-content";

const url = `http://www.techsolver.in/http-api.php?username=abc&password=pwd&senderid=MYID&route=1&number=${phone}&message=${message}`

console.log(url);

However, if…

Why node has a querystring module, to perform tasks that, at first glance, seem trivial.

Top comments (0)