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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@scrypted/node-pty

v1.0.9

Published

Fork pseudoterminals in Node.JS

Downloads

2,728

Readme

node-pty

Build Status

forkpty(3) bindings for node.js. This allows you to fork processes with pseudoterminal file descriptors. It returns a terminal object which allows reads and writes.

This is useful for:

  • Writing a terminal emulator (eg. via xterm.js).
  • Getting certain programs to think you're a terminal, such as when you need a program to send you control sequences.

node-pty supports Linux, macOS and Windows. Windows support is possible by utilizing the Windows conpty API on Windows 1809+ and the winpty library in older version.

API

The full API for node-pty is contained within the TypeScript declaration file, use the branch/tag picker in GitHub (w) to navigate to the correct version of the API.

Example Usage

import * as os from 'node:os';
import * as pty from 'node-pty';

const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';

const ptyProcess = pty.spawn(shell, [], {
  name: 'xterm-color',
  cols: 80,
  rows: 30,
  cwd: process.env.HOME,
  env: process.env
});

ptyProcess.onData((data) => {
  process.stdout.write(data);
});

ptyProcess.write('ls\r');
ptyProcess.resize(100, 40);
ptyProcess.write('ls\r');

Real-world Uses

node-pty powers many different terminal emulators, including:

  • Microsoft Visual Studio Code
  • Hyper
  • Upterm
  • Script Runner for Atom.
  • Theia
  • FreeMAN file manager
  • terminus - An Atom plugin for providing terminals inside your Atom workspace.
  • x-terminal - Also an Atom plugin that provides terminals inside your Atom workspace.
  • Termination - Also an Atom plugin that provides terminals inside your Atom workspace.
  • atom-xterm - Also an Atom plugin that provides terminals inside your Atom workspace.
  • electerm Terminal/SSH/SFTP client(Linux, macOS, Windows).
  • Extraterm
  • Wetty Browser based Terminal over HTTP and HTTPS
  • nomad
  • DockerStacks Local LAMP/LEMP stack using Docker
  • TeleType: cli tool that allows you to share your terminal online conveniently. Show off mad cli-fu, help a colleague, teach, or troubleshoot.
  • mesos-term: A web terminal for Apache Mesos. It allows to execute commands within containers.
  • Commas: A hackable terminal and command runner.
  • ENiGMA½ BBS Software: A modern BBS software with a nostalgic flair!
  • Tinkerun: A new way of running Tinker.
  • Tess: Hackable, simple and rapid terminal for the new era of technology 👍
  • NxShell: An easy to use new terminal for Windows/Linux/MacOS platform.
  • OpenSumi: A framework helps you quickly build Cloud or Desktop IDE products.

Do you use node-pty in your application as well? Please open a Pull Request to include it here. We would love to have it in our list.

Building

# Install dependencies and build C++
npm install
# Compile TypeScript -> JavaScript
npm run build

Dependencies

Node.JS 16 or Electron 19 is required to use node-pty. What version of node is supported is currently mostly bound to whatever version Visual Studio Code is using.

Linux (apt)

sudo apt install -y make python build-essential

macOS

Xcode is needed to compile the sources, this can be installed from the App Store.

Windows

npm install requires some tools to be present in the system like Python and C++ compiler. Windows users can easily install them by running the following command in PowerShell as administrator. For more information see https://github.com/felixrieseberg/windows-build-tools:

npm install --global --production windows-build-tools

The following are also needed:

  • Windows SDK - only the "Desktop C++ Apps" components are needed to be installed

Debugging

The wiki contains instructions for debugging node-pty.

Security

All processes launched from node-pty will launch at the same permission level of the parent process. Take care particularly when using node-pty inside a server that's accessible on the internet. We recommend launching the pty inside a container to protect your host machine.

Thread Safety

Note that node-pty is not thread safe so running it across multiple worker threads in node.js could cause issues.

Flow Control

Automatic flow control can be enabled by either providing handleFlowControl = true in the constructor options or setting it later on:

const PAUSE = '\x13';   // XOFF
const RESUME = '\x11';  // XON

const ptyProcess = pty.spawn(shell, [], {handleFlowControl: true});

// flow control in action
ptyProcess.write(PAUSE);  // pty will block and pause the child program
...
ptyProcess.write(RESUME); // pty will enter flow mode and resume the child program

// temporarily disable/re-enable flow control
ptyProcess.handleFlowControl = false;
...
ptyProcess.handleFlowControl = true;

By default PAUSE and RESUME are XON/XOFF control codes (as shown above). To avoid conflicts in environments that use these control codes for different purposes the messages can be customized as flowControlPause: string and flowControlResume: string in the constructor options. PAUSE and RESUME are not passed to the underlying pseudoterminal if flow control is enabled.

Troubleshooting

Powershell gives error 8009001d

Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.

This happens when PowerShell is launched with no SystemRoot environment variable present.

ConnectNamedPipe failed: Windows error 232

This error can occur due to anti-virus software intercepting winpty from creating a pty. To workaround this you can exclude this file from your anti-virus scanning node-pty\build\Release\winpty-agent.exe

pty.js

This project is forked from chjj/pty.js with the primary goals being to provide better support for later Node.js versions and Windows.

License

Copyright (c) 2012-2015, Christopher Jeffrey (MIT License). Copyright (c) 2016, Daniel Imms (MIT License). Copyright (c) 2018, Microsoft Corporation (MIT License).