promise
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
asap | 2.0.6 | 11.14 kB | MIT | prod |
Promise is a popular npm package that provides a simple implementation of Promises. It is a superset of ES6 Promises designed to offer readable and performant code while only including the essential extensions for using promises effectively in JS applications today. It adheres to the Promises/A+ implementation standard. The aim of this package is to deliver a smooth experience when working with asynchronous programming in JavaScript.
To make use of the Promise package in your project, you must first install it to your server using the command npm install promise
. From there, you can require it in your JavaScript file.
Here's an example snippet of how to use Promise:
var Promise = require('promise');
var promise = new Promise(function (resolve, reject) {
get('http://www.google.com', function (err, res) {
if (err) reject(err);
else resolve(res);
});
});
You can also choose to use part of the features or require a pure ES6 polyfill with the following syntax:
var Promise = require('promise/lib/es6-extensions');
To handle unhandled rejections and errors, the package provides methods that can be enabled during development. For example:
require('promise/lib/rejection-tracking').enable();
Please note that direct usage of underscore (_
) prefixed properties exposed by this Promise is discouraged as doing so may break your code with each new release.
You can find the Promise package's documentation at https://www.promisejs.org/api/. The documentation provides detailed information and examples on using the Promise package, including API references, usage examples, information about static and prototype functions, unhandled rejections, and more. It's a valuable resource for understanding and implementing promises effectively in your JavaScript application.