### Building and Running NeverBounce Examples as JavaScript Source: https://github.com/neverbounce/neverbounceapi-nodejs/blob/master/README.md These commands illustrate the process of compiling the TypeScript-based NeverBounce library into JavaScript and then executing a compiled example. `npm run build` compiles the project, and `node dist/examples/account-info.js` runs a specific JavaScript example from the compiled output directory. ```bash # Build the project npm run build # Run an example (after compilation) node dist/examples/account-info.js ``` -------------------------------- ### Running NeverBounce Examples Directly with TypeScript Source: https://github.com/neverbounce/neverbounceapi-nodejs/blob/master/README.md This command demonstrates how to execute a TypeScript example directly using the `npm run example` script, which typically leverages `ts-node`. This method bypasses the need for a separate compilation step, allowing for quicker execution of TypeScript examples. ```bash npm run example examples/single-check.ts ``` -------------------------------- ### Installing NeverBounce NodeJS Package Source: https://github.com/neverbounce/neverbounceapi-nodejs/blob/master/README.md This command installs the NeverBounce NodeJS wrapper package using npm, saving it as a dependency in your project's `package.json` file. This is the standard way to add the library to your Node.js project. ```Bash $ npm install neverbounce --save ``` -------------------------------- ### Verifying Email with NeverBounce API using Async/Await in TypeScript Source: https://github.com/neverbounce/neverbounceapi-nodejs/blob/master/README.md This example demonstrates how to initialize the NeverBounce client with an API key, perform an email verification check using `async/await`, and access detailed results including address and credit information. It also includes robust error handling for common API issues like authentication, referrer, and throttling errors. ```TypeScript import NeverBounce from 'neverbounce'; // Initialize NeverBounce client const client = new NeverBounce({apiKey: 'secret_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}); // Verify an email with async/await async function verifyEmail() { try { // You can request additional information like address_info and credits_info const result = await client.single.check('support@neverbounce.com', true, true); console.log('Result: ' + result.getResult()); // prints: "valid" console.log('Result (numeric): ' + result.getNumericResult()); console.log('Is Valid? ' + result.is(NeverBounce.result.valid)); // Access the response data with proper typing const response = result.getResponse(); if (response.address_info) { console.log('Host: ' + response.address_info.host); } if (response.credits_info) { console.log('Free Credits Used: ' + response.credits_info.free_credits_used); console.log('Paid Credits Used: ' + response.credits_info.paid_credits_used); } } catch (err) { // Errors are thrown and can be caught to handle specific error types if (err instanceof Error) { switch(err.type) { case NeverBounce.errors.AuthError: // The API credentials used are bad, have you reset them recently? break; case NeverBounce.errors.BadReferrerError: // The script is being used from an unauthorized source, you may need to // adjust your app's settings to allow it to be used from here break; case NeverBounce.errors.ThrottleError: // Too many requests in a short amount of time, try again shortly or adjust // your rate limit settings for this application in the dashboard break; case NeverBounce.errors.GeneralError: // A non recoverable API error occurred check the message for details break; default: // Other non specific errors console.error('Error:', err.message); break; } } else { console.error('Unknown error:', err); } } } verifyEmail(); ``` -------------------------------- ### Setting NeverBounce API Key Environment Variable Source: https://github.com/neverbounce/neverbounceapi-nodejs/blob/master/README.md This snippet shows the format for setting the `NEVERBOUNCE_API_KEY` environment variable in a `.env` file. This key is required for authenticating requests to the NeverBounce API. Users should replace the placeholder with their actual API key. ```plaintext NEVERBOUNCE_API_KEY=secret_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` -------------------------------- ### Verifying Email with NeverBounce API using Promises (TypeScript) Source: https://github.com/neverbounce/neverbounceapi-nodejs/blob/master/README.md This snippet demonstrates how to initialize the NeverBounce client and perform a single email verification using the Promise-based `then/catch` syntax. It shows how to access verification results, numeric results, check validity against NeverBounce constants, and properly handle various API errors with type checking. The `single.check` method takes the email, `address_info` flag, and `credits_info` flag as parameters. ```ts import NeverBounce from 'neverbounce'; // Initialize NeverBounce client const client = new NeverBounce({apiKey: 'secret_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}); // Verify an email with Promise syntax client.single.check('support@neverbounce.com', true, true) .then(result => { console.log('Result: ' + result.getResult()); // prints: "valid" console.log('Result (numeric): ' + result.getNumericResult()); console.log('Is Valid? ' + result.is(NeverBounce.result.valid)); // Access the response data with proper typing const response = result.getResponse(); if (response.address_info) { console.log('Host: ' + response.address_info.host); } }) .catch(err => { // Handle errors with type checking if (err instanceof Error) { switch(err.type) { case NeverBounce.errors.AuthError: console.error('Auth Error:', err.message); break; case NeverBounce.errors.BadReferrerError: console.error('Bad Referrer Error:', err.message); break; case NeverBounce.errors.ThrottleError: console.error('Throttle Error:', err.message); break; case NeverBounce.errors.GeneralError: console.error('General Error:', err.message); break; default: console.error('Error:', err.message); break; } } else { console.error('Unknown error:', err); } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.