Open URLs via Operating System

1.1.1 · abandoned · verified Wed Apr 22

The `openurl` package provides a simple Node.js module to programmatically open URLs, `mailto:` links, or local files using the operating system's default applications. For instance, `http` links will open in the default web browser, and `mailto` links in the default email client. The package's current and final stable version is `1.1.1`, which was last published over 10 years ago in January 2016. Consequently, `openurl` is no longer actively maintained and does not receive updates, bug fixes, or new features. While it may still function for basic use cases in CommonJS environments, it lacks modern features like native ECMAScript Modules (ESM) support and may have unaddressed platform-specific issues. Developers are strongly encouraged to use actively maintained alternatives like the `open` package (by Sindre Sorhus) for better cross-platform compatibility, ESM support, and ongoing reliability.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to open a web URL, compose an email using a mailto link with multiple recipients, subject, and body, and open a local file path using the operating system's default applications.

const openurl = require('openurl');

// Open a URL in the default web browser
openurl.open('https://www.google.com').then(() => {
  console.log('Opened Google in browser.');
}).catch(err => {
  console.error('Failed to open URL:', err.message);
});

// Open a mailto link in the default email client with recipients, subject, and body
openurl.mailto(['john.doe@example.com', 'jane.smith@example.com'], {
    subject: 'Important Inquiry',
    body: 'Dear recipients,\n\nThis is an automatically generated email.\n\nRegards,\nYour App'
}).then(() => {
  console.log('Opened mail client for email.');
}).catch(err => {
  console.error('Failed to open mailto link:', err.message);
});

// Example of opening a local file (path should be absolute for best results)
// Note: This often opens a directory viewer on some OS if it's a directory path.
// On macOS, it might open the directory in Finder. On Windows, in Explorer.
const filePath = process.platform === 'win32' ? 'C:\\Windows' : '/tmp';
openurl.open(filePath).then(() => {
  console.log(`Opened file/directory: ${filePath}`);
}).catch(err => {
  console.error('Failed to open file/directory:', err.message);
});

view raw JSON →