title: How to use exec() in nodejs
body: <p>I have this procedure <code>xyz_users_list</code> and it return list of users with <code>exec xyz_users_list</code> but how do i use it in nodejs app?</p>
  
  <h1>Code</h1>
  
  <p><code>index.js</code></p>
  
  <pre><code>'use strict';
  
  const express = require('express');
  const app = express();
  const mysql = require('mysql');
  var connection = require('express-myconnection');
  require('dotenv').config();
  
  app.use(
      connection(mysql, {
          host: process.env.DB_HOST,
          user: process.env.DB_USERNAME,
          password: process.env.DB_PASSWORD,
          database: process.env.DB_DATABASE
      }, 'request')
  );
  
  app.get('/', (req, res) =&gt; {
      return res.sendFile(__dirname + '/index.html');
  });
  
  //all users
  var Users = require('./routes/Users');
  app.get('/users', Users.list);
  </code></pre>
  
  <p><code>Users.js</code></p>
  
  <pre><code>'use strict';
  
  var response = require('../res');
  const { exec } = require('child_process');
  
      exports.list = function(req, res) {
          req.getConnection(function(err, connection) {
              connection.query(exec('xyz_users_list'), function(err, rows) {
                  if (err)
                      console.log("%s ", err);
  
                  response.success(rows, res);
              });
          });
      };
  </code></pre>
  
  <p>this code returns:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'query' of undefined</p>
  </blockquote>
  
  <p><em>If I use code below it works just fine but since i want to use <code>exec</code> it's returning error.</em></p>
  
  <pre><code>exports.list = function(req, res) {
          req.getConnection(function(err, connection) {
              connection.query('SELECT * FROM `users`', function(err, rows) {
                  if (err)
                      console.log("%s ", err);
  
                  response.success(rows, res);
              });
          });
      };
  </code></pre>
  
  <p>any idea?</p>
  
  <h1>Update</h1>
  
  <p>here is result of my <code>exec xyz_users_list</code> in <code>SQLQuery</code></p>
  
  <p><a href="https://i.stack.imgur.com/ckjRu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ckjRu.png" alt="one"></a></p>