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 |
What is process env port?
List some events that fired by streams in node js?
Mention the framework most commonly used in node.js?
What is the request object in nodejs?
What is callback function example?
Explain the difference between readfile and createreadstream in node js?
What is NPM in Node.js?
How to send data from node js to html?
What is node application?
How do you create an environment variable?
Explain 'Path' module in Node.JS?
What are Node.js Http module limitations?