Promise can be used either in a Node.js environment or in a browser, to install for Node.js use the npm package manager:
npm install promise-lite
To use in the browser, you just need the src/promise.js
file and the
Subscribable library that is used to handle the pub-sub events
Promise uses internally.
The Promise
constructor in Node.js is required by:
var Promise = require('promise-lite');
In a browser, Promise will be declared in window
scope anyway so can just be used as Promise
.
Promises are used to make otherwise asynchronous actions chainable, by linking them together with the Promise that they will return a value at some point in the future.