title: Saving data to json using nodejs and cointicker
body: <p>Im learning nodejs and I'm creating a server to get the price of cryptocurrencies using a npm called Coin-Ticker. I want to use the data I'm getting in an Angular app but it's not displaying the data in the html. This is my code:</p>
  
  <p>server.js</p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const http = require('http');
  const bodyParser = require('body-parser');
  const coinTicker = require('coin-ticker');
  
  const api = require('./server/routes/api');
  
  const app = express();
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  
  app.use(express.static(path.join(__dirname, 'dist')));
  
  app.use('/api', api);
  
  app.get('*', (req, res) =&gt; {
    res.sendFile(path.join(__dirname, 'dist/index.html'));
  });
  
  
  const port = process.env.PORT || '3000';
  app.set('port', port);
  
  const server = http.createServer(app);
  
  server.listen(port, () =&gt; console.log(`API running on localhost:${port}`));
  </code></pre>
  
  <p>API.JS</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const coinTicker = require('coin-ticker');
  
  /* GET api listing. */
  router.get('/', (req, res) =&gt; {
    res.send('api works');
  });
  
  router.get((req, res) =&gt; {
    coinTicker('bitfinex', 'BTC_USD')
      .then(posts =&gt; {
        res.status(200).json(posts.data);
      })
      .catch(error =&gt; {
        res.status(500).send(error)
      });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Thanks for your help!</p>