Monday, 3 April 2017

cant set headers in node.js and how to send more no of servers in ssh connection

            app.get('/api/platforms2',function(req,res){
            var sshcommectionresult="came";
            c.connect({
              host: '10.254.27.9',
              port: 22,
               //debug: console.log,
               readyTimeout: 99999,
              username: 'fork',
              password:'fork' 
            });

            c.on('connect', function() {
              console.log('Connection :: connect');
            });
            c.on('ready', function(err) {
              console.log('Connection :: ready');
                if(err){
                    sshcommectionresult="Failed inside function"
                }
                else{
                    sshcommectionresult="Connected";
                }
            c.on('error', function(err) {
              console.log('Connection :: error :: ' + err);
              sshcommectionresult="wrong username";
            });
            c.on('end', function() {
              console.log('Connection :: end');

            });
            c.on('close', function(had_error) {
              console.log('Connection :: close');
            });
                res.json(sshcommectionresult);
            });
            });

//I am new to this node.js field.After I am getting connected once next time when I am trying to refresh the page.The data is not being loaded again.It is throwing an error "Cant set headers after they are sent".I have one more doubt if I want to check for more no of servers.How can I acheive dat??



via vinay

No comments:

Post a Comment