Open In App

How to pass Node.js Output to Web Interface ?

Most of the popular browsers today automatically handle the display of raw data output from API on the Web interface. To do this we just have to send the required data directly in API response and the browser will take care of the rest.

Modules Required:



Setting up environment and Execution:

Example: Now create a file where we will write down the code to display the output on web interface.






const express = require("express");
  
const app = express();
  
app.listen(5000, () => {
  console.log(`Server is up and running on 5000 ...`);
});
  
app.get("/", (req, res) => {
  
    let data = {
        name: "GFG",
        age: 18,
        male: true
    }
  
    res.send(data);
});

Output: To run node server, go to http://localhost:5000 in browser to see output.

node index.js

Article Tags :