0 votes

pass variable from nodejs to javascript

In the main file I have everything that runs to the server

const express = require("express");
const app = express();

app.use(express.static(__dirname +"/www/"));


but I would like to send variables to the client, but I don't know how to do it.


Ricardo Points 11

As I understand it, you can send information to the client in at least two ways. One is by creating routes so that it works as an api and you can return a Json object, the other is by using a template engine. I leave you two links one of the documentation of express where you can see how to create routes and the second of stackoverflow where they give a clear example of how to use templates and send variables to use them in the template.

Documentation express create routes

Send variables from the server to the client using templates

I hope you find it useful!


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: