0

Trying to a run Node.js as a Windows service. I have used nssm.exe to create the service, and it starts then immediately stops.

The error - "Could not resume ListenerNodeJS Service on Local Computer. The service did not return an error. This could be an internal Windows error or an internal service error. If the problem persists, contact your system administrator."

I have also tried using srvstart and that did the same thing, but this time the error was "the service has started and stop. Some Services stop automatically if they have no work to do" (etc...)

Here is the contents of listener.js (the javascript I wish to run as a service)

///////////////////////////////////////////////
// get the querystring
//////////////////////////////////////////////
var http = require("http"), querystring = require("querystring");
var dirName="";
var pathName="v:/Opportunities/";

http.createServer(function(req, res) {

    //parse everything after the "?" into key/value pairs
var qs = querystring.parse(req.url.split("?")[1]), 
        dirName =pathName + qs.dirName;
        html = "" + "Directory to write " + dirName;
        res.end(html);
        createDir(dirName);
        }).listen(1337, '0.0.0.0');

///////////////////////////////////////////////
// function: createDir  Creates a directory from the querystring
///////////////////////////////////////////////

function createDir(d){
    var fs = require('fs');
    //see if the directory exists
    if (!(fs.existsSync(d)))    { 
            console.log("Directory does not exists. Creating directory...");
            fs.mkdir(d);
            ///create sub folders
            fs.mkdir(d+"/Drawings");
            fs.mkdir(d+"/Pictures");
            fs.mkdir(d+"/PO_Contracts");
            fs.mkdir(d+"/Proposals");
            fs.mkdir(d+"/Quotes");
            fs.mkdir(d+"/SOW");
            fs.mkdir(d+"/Vendor_Quotes");
        }
        else {
            console.log("Directory exists.");
        }
    }
2
  • I was successfully able to add the service using nssm. However, it seems that code will not create directory when run as a service. It will run as command line only.
    – Ron Baylin
    May 20, 2013 at 22:33
  • SOLVED. I had to not use Program Files as the location of nodejs.exe. I simply copied nodejs directory over to another location (C:\nodejs) To solve the file diretory writing issue, I had to use a real disk letter, not a mapped drive. Mapping it wouldn't make sense to a service, so therefore I use the real drive letter.
    – Ron Baylin
    May 20, 2013 at 22:48

1 Answer 1

0

I had to not use Program Files as the location of nodejs.exe. I simply copied nodejs directory over to another location (C:\nodejs) To solve the file diretory writing issue, I had to use a real disk letter, not a mapped drive. Mapping it wouldn't make sense to a service, so therefore I use the real drive letter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.