title: How to get variable from exec function in Node.js
body: <p>I need to use the value of the variable <code>w1</code> and <code>h1</code> outside the <code>exec</code> function, in <code>console.log</code>.</p>
  
  <pre><code>exec(command, function(err, stdout, stderr) {
  
      var resolution = stdout.split("x");
      w1 = resolution[0];
      h1 = resolution[1];
  
  });
  
  console.log(w1 + " - " + h1);
  </code></pre>
  
  <p>The <code>console.log</code> displays the correct values ​​of the variables, but before displays this list of errors:</p>
  
  <pre><code>ReferenceError: w1 is not defined
  at app.js:30:21
  at callbacks (app/node_modules/express/lib/router/index.js:164:37)
  at param (app/node_modules/express/lib/router/index.js:138:11)
  at pass (app/node_modules/express/lib/router/index.js:145:5)
  at Router._dispatch (app/node_modules/express/lib/router/index.js:173:5)
  at Object.router (app/node_modules/express/lib/router/index.js:33:10)
  at next (app/node_modules/express/node_modules/connect/lib/proto.js:190:15)
  at Object.expressInit [as handle] (app/node_modules/express/lib/middleware.js:30:5)
  at next (app/node_modules/express/node_modules/connect/lib/proto.js:190:15)
  at Object.query [as handle] (app/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)
  </code></pre>
  
  <p>I found this similar question, but don't work for me.
  <a href="https://stackoverflow.com/questions/19442829/how-can-we-access-variable-from-callback-function-in-node-js">How can we access variable from callback function in node.js?</a></p>
  
  <p>Thank you.</p>