Skip to content
Related Articles

Related Articles

Improve Article
How to pass Node.js Output to Web Interface ?
  • Last Updated : 08 Apr, 2021

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:

  • express.js: To handle routing

Setting up environment and Execution:

  • Step 1: Initialize node project.
    npm init
  • Step 2: install required modules.
    npm install express

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

index.js




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

My Personal Notes arrow_drop_up
Recommended Articles
Page :