title: How to declare a var inside a function and use it outside?
body: <p><strong>I have this code:</strong></p>
  <pre><code>var logoPath;
  
  upload(req, res, (err) =&gt; {
      if(err) return res.status(200).send({ message: 'Error saving image.' });
  
      logoPath = req.file.filename;
  });
  
  console.log(logoPath) // undefined ???
  </code></pre>
  <p><strong>Upload function gets file information. So i want to save the filename in <em>logoPath</em> var but when i run the code it throws <em>undefined</em> how can i solve it?</strong></p>