title: UnhandledPromiseRejectionWarning, Express.js and Node.js
body: <p>I am completely new to <strong>Node.js</strong> and <strong>Express.js</strong> and have been trying to work through some examples to integrate the Shippo API into my E-commerce web app but I'm getting some errors that I just can't solve despite reviewing my code several times.</p>
  
  <p>I get the <strong>UnhandledPromiseRejectionWarning</strong> error, which, from I've read online, means that somewhere in my code there is something a <strong>.then()</strong> section which does not include a "catch" or a "what to-do" is the request returns an error. Any help would be greatly appreciated. </p>
  
  <p><strong>This is my code:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var express = require('express')
  var app = express()
  var http = require('http');
  var Raven = require('raven');
  var shippo = require('shippo')('ACCESS_TOKEN');
  var engines = require('consolidate');
  const bodyParser = require('body-parser');
  const path = require('path');
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(bodyParser.json());
  app.engine('html', engines.mustache);
  app.set('view engine', 'html');
  //app.use(express.static(path.join(_dirname,'/')));
  
  
  app.get('/', function (req, res) {
    res.render('Index.html');
  })
  app.post('/', function (req, res) {
  
    var addressFrom  = {
        "object_purpose":"PURCHASE",
        "name": "SENDER_NAME",
        "company":"Shippo",
        "street1":"215 Clayton St.",
        "city":"San Francisco",
        "state":"CA",
        "zip":"94117",
        "country":"US", //iso2 country code
        "phone":"+1 555 341 9393",
        "email":"SENDER_EMAIL",
    };
  
    // example address_to object dict
    var addressTo = {
        "object_purpose":"PURCHASE",
        "name": req.body.fnames + ' ' + req.body.lnames,
        "company": req.body.company,
        "street1":req.body.street,
        "city":req.body.city,
        "state":req.body.state,
        "zip":req.body.zipcode,
        "country": req.body.country, //iso2 country code
        "phone":"+1 555 341 9393",
        "email":"support@goshippo.com",
    };
  
    // parcel object dict
    var parcelOne = {
        "length":"5",
        "width":"5",
        "height":"5",
        "distance_unit":"in",
        "weight":"2",
        "mass_unit":"lb"
    };
  
  
    var shipment = {
        "object_purpose": "PURCHASE",
        "address_from": addressFrom,
        "address_to": addressTo,
        "parcels": [parcelOne],
        "submission_type": "DROPOFF"
    };
  
    shippo.transaction.create({
        "shipment": shipment,
        "servicelevel_token": "ups_standard",
        "carrier_account": 'CARRIER_TOKEN',
        "label_file_type": "PDF"
    })
    .then(function(transaction) {
        shippo.transaction.list({
          "rate": transaction.rate
        })
        .then(function(mpsTransactions) {
            mpsTransactions.results.forEach(function(mpsTransaction){
                if(mpsTransaction.object_status == "SUCCESS") {
                    console.log("Label URL: %s", mpsTransaction.label_url);
                    console.log("Tracking Number: %s", mpsTransaction.tracking_number);
                    console.log("E-Mail: %s", mpsTransaction.object_owner);
                    console.log(mpsTransaction.object_status);
                    res.status(200).send("Label can be found under: " + mpsTransaction.label_url);
                } else {
                    // hanlde error transactions
                    console.log("Message: %s", mpsTransactions.messages);
                }
            });
        })
    }, function(err) {
        // Deal with an error
        console.log("There was an error creating transaction : %s", err.detail);
        res.send("something happened :O")
    });
  })
  app.post('/successp', function (req, res) {
  
    var token = req.body.stripeToken; // Using Express
    // Charge the user's card:
  var charge = stripe.charges.create({
    amount: 1000,
    currency: "eur",
    description: "Example charge",
    source: token,
  }, function(err, charge) {
    // asynchronously called
  });
   res.send('Thanks!')
  })
  app.post('/successp', function (req, res) {
  
    var token = req.body.stripeToken; // Using Express
    // Charge the user's card:
  var charge = stripe.charges.create({
    amount: 1000,
    currency: "eur",
    description: "Example charge",
    source: token,
  }, function(err, charge) {
    // asynchronously called
  });
   res.send('Thanks!')
  })
  
  app.listen(3000, function () {
    console.log('Example app listening on port 3000!')
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>And this is the Error I get:</strong></p>
  
  <blockquote>
    <p>Example app listening on port 3000!
    (node:2378) UnhandledPromiseRejectionWarning
    (node:2378) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
    (node:2378) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.</p>
  </blockquote>
  
  <p>I'm also not completely sure about the purpose for some of the lines (again, i'm very new to express and node.js). What is engine and mustache? also, I see that this sample code uses <strong>APP.POST('/succesp', function(req, res)...)</strong>, what exactly is that <strong>'/succesp'</strong>? Another html file I need to create? Also, what is that "<strong>app.use(express.statc([ath.join(_dirnam,'/')));</strong>"  at the beginning?</p>