npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

postnl-connect-kit

v1.0.0

Published

Node.js SDK for PostNL API - Shipping, Tracking, Pricing and more

Downloads

14

Readme

PostNL Connect Kit

🇳🇱 A comprehensive Node.js SDK for the PostNL API, supporting shipping, tracking, pricing, and more.

Features

Barcode Generation - Generate barcodes for shipments
Shipping & Labelling - Create shipping labels
Price Calculation - Calculate shipping costs
Delivery Timeframes - Get delivery time estimates
Location Finder - Find PostNL pickup locations
Track & Trace - Track shipment status
TypeScript Support - Full TypeScript support with type definitions
Sandbox Mode - Test environment for development

Installation

npm install postnl-connect-kit

Quick Start

const PostNL = require('postnl-connect-kit');

// Initialize the client
const postnl = new PostNL({
  apiKey: 'your-api-key',
  customerNumber: 'your-customer-number',
  customerCode: 'your-customer-code',
  sandbox: true // Use false for production
});

// Calculate shipping price
const price = await postnl.checkout.calculatePrice(
  '1012JS',  // Postal code
  '1',       // House number
  'NL'       // Country code
);

console.log('Shipping options:', price.Options);

Usage Examples

1. Price Calculation

// Get cheapest delivery option
const cheapest = await postnl.checkout.getCheapestOption(
  '1012JS',
  '1',
  'NL'
);

console.log(`Cheapest: €${cheapest.price} on ${cheapest.date}`);

// Get all delivery options with prices
const options = await postnl.checkout.calculatePrice(
  '1012JS',
  '1',
  'NL'
);

options.Options.forEach(option => {
  console.log(`Date: ${option.Date}`);
  option.Timeframes.forEach(tf => {
    console.log(`  ${tf.From}-${tf.To}: €${tf.Price?.Amount}`);
  });
});

2. Generate Barcode

// Generate single barcode
const barcode = await postnl.barcode.generate('NL');
console.log('Barcode:', barcode);

// Generate multiple barcodes
const barcodes = await postnl.barcode.generateMultiple(5, 'NL');
console.log('Barcodes:', barcodes);

3. Create Shipment and Label

const shipment = {
  Addresses: [
    {
      AddressType: '01', // Receiver
      City: 'Amsterdam',
      Countrycode: 'NL',
      HouseNr: '1',
      Street: 'Singel',
      Zipcode: '1012JS',
      Name: 'Jan Jansen',
      CompanyName: 'PostNL',
    },
    {
      AddressType: '02', // Sender
      City: 'Rotterdam',
      Countrycode: 'NL',
      HouseNr: '1',
      Street: 'Coolsingel',
      Zipcode: '3011AD',
      Name: 'Piet Pietersen',
    }
  ],
  Barcode: barcode,
  Dimension: {
    Weight: 2000, // grams
  },
  ProductCodeDelivery: '3085', // Standard shipment
  Reference: 'Order-12345',
};

const label = await postnl.shipping.createShipment(shipment);
console.log('Label created:', label.ResponseShipments[0].Labels[0].Content);

4. Track Package

// Track a shipment
const status = await postnl.tracking.track('3SDEVC123456789');

console.log('Status:', status.StatusDescription);
console.log('Phase:', status.PhaseDescription);

// Check if delivered
const delivered = await postnl.tracking.isDelivered('3SDEVC123456789');
console.log('Is delivered?', delivered);

// Get delivery history
const history = await postnl.tracking.getHistory('3SDEVC123456789');
history.forEach(event => {
  console.log(`${event.timestamp}: ${event.description}`);
});

5. Find Locations

// Find pickup locations by postal code
const locations = await postnl.locations.findByPostalCode('1012JS', 'NL');

locations.forEach(loc => {
  console.log(`${loc.Name} - ${loc.Distance}m away`);
  console.log(`  ${loc.Address.Street} ${loc.Address.HouseNumber}`);
});

// Find by city
const cityLocations = await postnl.locations.findByCity('Amsterdam', 'NL');

6. Delivery Timeframes

// Get timeframes for today
const timeframes = await postnl.timeframes.getTimeframesToday(
  '1012JS',
  'NL',
  '1'
);

timeframes.forEach(tf => {
  console.log(`Date: ${tf.Date}`);
  tf.Timeframes.forEach(slot => {
    console.log(`  ${slot.From}-${slot.To}`);
  });
});

// Get timeframes for next 5 days
const nextDays = await postnl.timeframes.getTimeframesNextDays(
  5,
  '1012JS',
  'NL'
);

API Reference

Configuration

interface PostNLConfig {
  apiKey: string;              // Your PostNL API key
  sandbox?: boolean;           // Use sandbox (default: false)
  customerNumber?: string;     // Your customer number
  customerCode?: string;       // Your customer code
  collectionLocation?: string; // Collection location code
}

Services

  • postnl.barcode - Barcode generation
  • postnl.shipping - Create shipments and labels
  • postnl.checkout - Calculate prices and delivery options
  • postnl.timeframes - Get delivery timeframes
  • postnl.locations - Find pickup locations
  • postnl.tracking - Track shipments

Product Codes

const ProductCode = {
  STANDARD: '3085',              // Standard delivery
  MAILBOX: '2928',              // Mailbox package
  EVENING: '3089',              // Evening delivery
  SUNDAY: '3389',               // Sunday delivery
  MORNING: '3385',              // Morning delivery
  SAMEDAY: '3189',              // Same day delivery
  INTERNATIONAL_STANDARD: '4945', // International standard
  INTERNATIONAL_TRACKED: '4952',  // International tracked
};

Error Handling

try {
  const barcode = await postnl.barcode.generate('NL');
} catch (error) {
  console.error('Error:', error.message);
}

TypeScript Support

This library is fully written in TypeScript and includes all type definitions:

import PostNL, { PostNLConfig, ShipmentRequest, ProductCode } from 'postnl-connect-kit';

const config: PostNLConfig = {
  apiKey: 'your-key',
  sandbox: true,
};

const postnl = new PostNL(config);

Environment Variables

POSTNL_API_KEY=your-api-key
POSTNL_CUSTOMER_NUMBER=your-customer-number
POSTNL_CUSTOMER_CODE=your-customer-code
POSTNL_SANDBOX=true

🧪 Testing

This project includes comprehensive tests with 19 unit tests covering all major features.

Running Tests

# Run all tests
npm test

# Run tests with coverage
npm test -- --coverage

# Run tests in watch mode
npm test -- --watch

Test Results

✅ Test Suites: 4 passed, 4 total
✅ Tests:       19 passed, 19 total
✅ Coverage:    53% statements, 41% branches

Tests include:

  • ✅ Barcode Generation
  • ✅ Price Calculation (Checkout)
  • ✅ Shipment Tracking
  • ✅ SDK Initialization

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Support

For issues and questions:

Changelog

v1.0.0

  • ✅ Initial release
  • ✅ Barcode generation
  • ✅ Shipping & labelling
  • ✅ Price calculation
  • ✅ Delivery timeframes
  • ✅ Location finder
  • ✅ Track & trace