The Wayback Machine - https://web.archive.org/web/20230213033905/https://www.geeksforgeeks.org/how-to-pass-node-js-output-to-web-interface/
Skip to content
Related Articles
Open in App
Not now

Related Articles

How to pass Node.js Output to Web Interface ?

Improve Article
Save Article
  • Last Updated : 22 Sep, 2021
Improve Article
Save Article

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 interface.

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
Related Articles

Start Your Coding Journey Now!