How to send data from node js to html?



How to send data from node js to html?..

Answer / Devendra Dangwal

To send data from Node.js to HTML, you can use Express.js and EJS (Embedded JavaScript) templates. First, install EJS using npm: `npm install ejs`. Then create an 'views' folder in your project directory and create an 'index.ejs' file inside it with your HTML structure. To render the HTML and pass data, update 'app.js':
```javascript
const express = require('express');
const app = express();
app.set('view engine', 'ejs');

app.get('/', function(req, res) {
const data = { message: 'Hello World!' };
res.render('index', data);
});

app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Node.js Interview Questions

What is process env port?

1 Answers  


List some events that fired by streams in node js?

1 Answers  


Mention the framework most commonly used in node.js?

1 Answers  


What is the request object in nodejs?

1 Answers  


What is callback function example?

1 Answers  


Explain the difference between readfile and createreadstream in node js?

1 Answers  


What is NPM in Node.js?

1 Answers  


How to send data from node js to html?

1 Answers  


What is node application?

1 Answers  


How do you create an environment variable?

1 Answers  


Explain 'Path' module in Node.JS?

1 Answers  


What are Node.js Http module limitations?

1 Answers  


Categories