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

pm2-windows-service-nosetup

v0.1.1

Published

Install PM2 as a service on windows. Based on pm2-windows-service from jon-hall at 0.2.1

Downloads

2

Readme

pm2-windows-service-nosetup

Allows easily installing and uninstalling PM2 as a service on Windows machines - inspired by pm2-windows-startup, and largely achieved using node-windows.

NOTE: The documentation may not be relevant for the configuration bits. We ripped out the interactive setup and thus you're on your own. Take this :hocho:

npm i pm2-windows-service-nosetup -g

NOTE: pm2-windows-service-nosetup currently requires node v4.0.0+, if node v0.12.x support is a requirement for you, please post in this issue.

Install and Uninstall the Service

TIP: Run these from an administrative command prompt to avoid getting hit with a bunch of UAC dialogs

pm2-service-install-nosetup [-n <service name>]

pm2-service-uninstall-nosetup

The install command also offers to perform some basic setup for you which helps address some of the caveats detailed below.

Quickstart

After reading the caveats section, use PM2 to start the set of processes that you want the service to restore, and then just do:

pm2 save

The service will then restart that set of processes when the service is next started (by default this will be on system boot).

Configuration

You can control what the PM2 service runs using the PM2_SERVICE_SCRIPTS environment variable, which should be set to a semi-colon separated list of javascript files and/or json config files to run when the service starts (using pm2 start).

If PM2_SERVICE_SCRIPTS is not set, then the default behaviour is to call pm2 resurrect on service startup - when PM2 is running with the list of processes you want launched by the service, use pm2 save to dump the process list, ready for the service to restore it when it next starts.

Caveats

While testing this, a few caveats have arisen which need to be detailed upfront, as they can lead to issues when PM2 is installed as a service:

  • If you don't have the PM2_HOME environment variable set (in such a way that it is available to the service user - the simplest being set it at machine level), you might find PM2 attempting to run in strange directories. To resolve this, make sure you set the environment variable and restart the service - though see the comment just below about the location it points to being accessible for the service user.
  • If you run the service under one user account, and then attempt to interact with PM2 from the command line using a different account, you'll find things don't work as expected if the PM2_HOME environment variable contains any "user context" env vars (%APPDATA%, %USERPROFILE% etc.), or if one of the users cannot access the location of PM2_HOME.
    • To avoid this problem, either set PM2_HOME to an absolute path that all potential users (service and CLI) can write to, or run the service under the same account as you intend to use the CLI from.
  • It also seems PM2 throws an error when you try to use the CLI from a non-administrative command prompt after it has been launched as a service, regardless of which user the service runs under (not tested with a non-admin user, yet).
    • Currently, the workaround for this, unfortunately, is just use an administrative command prompt if you need to access PM2 via command line when it is running as a service.
  • As raised in #24, there appears to be a dependency on having .NET 3.5 installed on the machine on which the service runs (and this holds true even when later versions are installed, you still need 3.5 as well) - this issue is still under investigation but, while that's happening, this is something to bear in mind when setting up the service.
  • Lastly, when launching json config files using PM2_SERVICE_SCRIPTS, problems arise if the apps declared in the config file don't explicitly have a cwd set (it ends up being the home dir of the service user).
    • pm2-windows-service-nosetup attempts to solve this issue for you by automatically defaulting the cwd property to the directory of the config file when it isn't explicitly set, if this is an issue for you then explicitly setting the cwd for your apps might be what you need to do.

Logs

The service created by node-windows is currently placed in <global npm packages directory>/node_modules/pm2-windows-service-nosetup/src/daemon/, as such, this is also where you will find the log output from the service, should you need it.