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 🙏

© 2026 – Pkg Stats / Ryan Hefner

winsvc

v1.0.1

Published

一个专门用来在Windows系统上以服务方式运行NodeJS脚本的工具。 A tool designed to run NodeJS scripts in service mode on Windows system. ## 安装(Installation) ``` npm install -g winsvc ``` ## 用法(Usage) 安装服务(Install Service) ``` winsvc -i ServiceName ScriptPath ``` 卸载服务(Uni

Readme

winsvc

一个专门用来在Windows系统上以服务方式运行NodeJS脚本的工具。 A tool designed to run NodeJS scripts in service mode on Windows system.

安装(Installation)

npm install -g winsvc

用法(Usage)

安装服务(Install Service)

winsvc -i ServiceName ScriptPath

卸载服务(Uninstall Service)

winsvc -u ServiceName

日志文件deamon.log将会在ScriptPath目录中生成。 The log file deamon.log will be generated in the scriptpath directory.

bin文件源码(Bin File Source)

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;

namespace winsvc
{
    partial class WinSvc : ServiceBase
    {
        string fullPath = string.Empty;
        string directory = string.Empty;
        string logFile = string.Empty;
        string[] args;

        Process process = null;
        private bool running = false;
        private object locker = new object();

        public WinSvc(string[] args)
        {
            InitializeComponent();
            this.args = args;
            if (args.Length > 0) fullPath = string.Join(" ", args);
            directory = Path.GetDirectoryName(fullPath);
            string file = Path.GetFileName(fullPath);
            if (!File.Exists(fullPath)) throw new Exception("目标文件不存在");
            logFile = Path.Combine(directory, "deamon.log");
        }

        protected override void OnStart(string[] args)
        {
            Start();
        }

        protected override void OnStop()
        {
            if (process != null && !process.HasExited)
            {
                RunCmd("taskkill /F /PID " + process.Id + " /T");
            }
            if (running)
            {
                running = false;
                WriteLine("Service Stopping");
            }
            else
            {
                WriteLine("Service Stopped");
            }
        }

        public void Start()
        {
            running = true;
            WriteLine("Service Start");
            new Thread(Run).Start();
        }

        private void Run()
        {
            while (running)
            {
                try
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.WorkingDirectory = directory;
                    startInfo.FileName = "node.exe";
                    startInfo.UseShellExecute = false;
                    startInfo.CreateNoWindow = true;
                    startInfo.RedirectStandardOutput = true;
                    startInfo.RedirectStandardError = true;
                    startInfo.StandardOutputEncoding = Encoding.UTF8;
                    startInfo.StandardErrorEncoding = Encoding.UTF8;
                    startInfo.Arguments = string.Join(" ", args);
                    process = Process.Start(startInfo);
                    process.OutputDataReceived += (s, e) =>
                    {
                        if (!string.IsNullOrEmpty(e.Data)) { WriteLine(e.Data); }
                    };
                    process.ErrorDataReceived += (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { WriteLine(e.Data); } };
                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    WriteLine("Process Start {0}", process.Id);
                    while (running)
                    {
                        if (process.HasExited)
                        {
                            WriteLine("Process Exit {0}", process.Id);
                            break;
                        }
                        Thread.Sleep(1000);
                    }
                }
                catch (Exception e)
                {
                    WriteLine(e);
                }
            }
            Stop();
        }

        private void RunCmd(string command)
        {
            Process process = new Process();
            process.StartInfo.FileName = "cmd.exe";
            process.StartInfo.Arguments = "/c " + command;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.Start();
            process.OutputDataReceived += (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { WriteLine(e.Data); } };
            process.ErrorDataReceived += (s, e) => { if (!string.IsNullOrEmpty(e.Data)) { WriteLine(e.Data); } };
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
        }

        private void WriteLine(Exception e)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(e.Message);
            string[] stackTraces = e.StackTrace.Split('\n');
            for (int i = 0; i < stackTraces.Length; i++)
            {
                if (stackTraces[i].Contains("winsvc"))
                {
                    sb.Append("\r\n" + stackTraces[i].Trim());
                    break;
                }
            }
            WriteLine(sb.ToString());
        }

        private void WriteLine(string format, params object[] args)
        {
            WriteLine(string.Format(format, args));
        }

        private void WriteLine(string msg)
        {
            lock (locker)
            {
                StreamWriter sw = null;
                try
                {
                    string message = string.Format("[{0}] {1}", DateTime.Now.ToString("MM/dd HH:mm:ss.fff"), msg);
                    Debug.WriteLine(message);
                    sw = new StreamWriter(logFile, true);
                    sw.WriteLine(message);
                    FileInfo fileinfo = new FileInfo(logFile);
                    if (fileinfo.Length > 2097152)
                    {
                        sw.Close();
                        string all = File.ReadAllText(logFile);
                        string[] lines = all.Split('\n');
                        int size = Convert.ToInt32(lines.Length / 2);
                        string[] linesNew = lines.Skip(size).ToArray();
                        File.Delete(logFile);
                        File.WriteAllText(logFile, string.Join("\n", linesNew));
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Close();
                    }
                }
            }
        }
    }
}

问题反馈(Feedback)

[email protected]