Installations
npm install node-pty
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.20.0
NPM Version
8.19.4
Score
92.3
Supply Chain
100
Quality
93.1
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Languages
TypeScript (49.85%)
C++ (38.86%)
JavaScript (8.25%)
Python (1.86%)
C (1.19%)
Developer
microsoft
Download Statistics
Total Downloads
58,487,031
Last Day
29,933
Last Week
121,713
Last Month
605,679
Last Year
6,259,597
GitHub Statistics
1,514 Stars
1,172 Commits
253 Forks
30 Watching
21 Branches
134 Contributors
Bundle Size
20.08 kB
Minified
5.64 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.0
Package Id
node-pty@1.0.0
Unpacked Size
1.09 MB
Size
244.74 kB
File Count
251
NPM Version
8.19.4
Node Version
16.20.0
Publised On
12 Jun 2023
Total Downloads
Cumulative downloads
Total Downloads
58,487,031
Last day
-2.5%
29,933
Compared to previous day
Last week
-20.8%
121,713
Compared to previous week
Last month
10.1%
605,679
Compared to previous month
Last year
-63%
6,259,597
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
node-pty
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
1var os = require('os'); 2var pty = require('node-pty'); 3 4var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash'; 5 6var ptyProcess = pty.spawn(shell, [], { 7 name: 'xterm-color', 8 cols: 80, 9 rows: 30, 10 cwd: process.env.HOME, 11 env: process.env 12}); 13 14ptyProcess.onData((data) => { 15 process.stdout.write(data); 16}); 17 18ptyProcess.write('ls\r'); 19ptyProcess.resize(100, 40); 20ptyProcess.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
1# Install dependencies and build C++ 2npm install 3# Compile TypeScript -> JavaScript 4npm 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)
1sudo 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:
1npm 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:
1const PAUSE = '\x13'; // XOFF 2const RESUME = '\x11'; // XON 3 4const ptyProcess = pty.spawn(shell, [], {handleFlowControl: true}); 5 6// flow control in action 7ptyProcess.write(PAUSE); // pty will block and pause the child program 8... 9ptyProcess.write(RESUME); // pty will enter flow mode and resume the child program 10 11// temporarily disable/re-enable flow control 12ptyProcess.handleFlowControl = false; 13... 14ptyProcess.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).
No vulnerabilities found.
Reason
3 commit(s) and 12 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
all changesets reviewed
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
1 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
Reason
binaries present in source code
Details
- Warn: binary detected: third_party/conpty/1.20.240626001/win10-arm64/OpenConsole.exe:1
- Warn: binary detected: third_party/conpty/1.20.240626001/win10-arm64/conpty.dll:1
- Warn: binary detected: third_party/conpty/1.20.240626001/win10-x64/OpenConsole.exe:1
- Warn: binary detected: third_party/conpty/1.20.240626001/win10-x64/conpty.dll:1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: npmCommand not pinned by hash: examples/electron/npm_install.sh:15
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Score
6.1
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to node-pty
node-pty-prebuilt-multiarch
Fork pseudoterminals in Node.JS
@faressoft/node-pty-prebuilt
A parallel fork of node-pty providing prebuilt packages for Node.js and Electron
@homebridge/node-pty-prebuilt-multiarch
Fork pseudoterminals in Node.JS
node-pty-prebuilt-multiarch-cp
Fork pseudoterminals in Node.JS