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

ntsuspend

v1.0.2

Published

Suspend and resume processes on Windows

Downloads

319

Readme

NtSuspend

Suspend and resume processes on Windows using NtSuspendProcess() and NtResumeProcess(). This is a Node.js only module, it won't run in any browser or other JavaScript environments.

This project includes TypeScript declarations.

Feel free to ask anything by opening an issue on GitHub.

Only NodeJS 10.x or higher is supported

Install

The library can be installed from NPM or from GitHub:

npm i ntsuspend

npm i FedericoCarboni/node-ntsuspend

To use it in your project you can import or require() it.

import { suspend, resume } from 'ntsuspend';
const { suspend, resume } = require('ntsuspend');

Note: Make sure to use this package as an optional dependency if you want to support multiple operating systems. Optional imports in ESM can be achieved with top-level await, still unavailable in LTS releases, and dynamic import or by using createRequire().

if (process.platform === 'win32') {
  const ntsuspend = await import('ntsuspend');
  // ... use ntsuspend
}
import { createRequire } from 'module';

if (process.platform === 'win32') {
  const ntsuspend = createRequire(import.meta.url)('ntsuspend');
  // ... use ntsuspend
}

In CommonJS require() can already be used conditionally.

if (process.platform === 'win32') {
  const ntsuspend = require('ntsuspend');
  // ... use ntsuspend
}

Usage

The package exports suspend() and resume(), they take the process' PID and return true on success, false otherwise.

if (!suspend(pid))
  console.log('Could not suspend process');
if (!resume(pid))
  console.log('Could not resume process');

If you are using Node.js' child processes the process id can be obtained by using subprocess.pid. Note: make sure that you're passing the actual process id to ntsuspend; the ChildProcess instance returned by child_process.exec is a handle to the shell not to the actual subprocess. Use child_process.spawn and make sure that the shell option is disabled. See #3.

const subprocess = spawn('executable');
if (!suspend(subprocess.pid))
  console.log('Could not suspend process');

Note: If you're not on Windows suspend() and resume() will be undefined.

Disclaimer

This library uses NtSuspendProcess() and NtResumeProcess() from NTDLL, these functions are not officially documented on MSDN; they have been consistently available since Windows XP, but are not guaranteed to work in the future.