javascript - How do I get to transfer an array from the server side to client side in node.js? -
i have following function on client side:
                //todo: fix                 var socket = io.connect('http://localhost:3000/home');                 socket.on('news', function (data) {                     console.log('testing: ' + data);                     //socket.emit('my other event', {my: 'data'});                 }); and following on server side:
module.exports = function(app, io) {      app.get('/home',function(req, res){         //res.render('profile.ejs');     });     io.on('connection', function(socket){         socket.emit('news', {         data: 'world'         }); }; the problem can't seem log received data client's console. what's wrong code?
use json.stringify() printing whole data in proper formate`
console.log('testing: ' + json.stringify(data)); 
Comments
Post a Comment