简体   繁体   中英

How can I pass Object Details to index.html using GET or POST method and show it in HTML <pre> tags

I have a socket object

var express = require('express');
var util = require('util');
var app = express();
var server = require('http').createServer(app);
var io = require("socket.io").listen(server);

Loading index.html

app.get("/", function(req, res){
        res.sendFile(__dirname+ "/index.html");
    })

For viewing what actual io Object contains, I am using util

var io_ObjectDetails = util.inspect(io, {showHidden: false, depth: null});

The question is How can I pass io_ObjectDetails to index.html using GET or POST method and show it in HTML tags

If i understand you correctly, you are trying to pass variables to a view. The method that does that is app.render or res.render

 app.get("/", function(req, res){
    res.render(__dirname+ "/index.html", io_ObjectDetails [, optional callback);
 })

You'll need to change your engine to render html with res.render . take a look at app.engine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM