coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.82k stars 356 forks source link

Error: Object expected #165

Closed alexya closed 7 years ago

alexya commented 7 years ago

I tried to use node-windows to run my JavaScript

first of all, I git clone the node-windows, and install to global

c:\src\node-windows>npm install -g node-windows
node-windows@0.1.14 C:\Users\Developer\AppData\Roaming\npm\node_modules\node-win
dows
├── xml@0.0.12
└── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)

and then create a script start_service.js under the folder with the content:

var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'Shadowsocks nodejs server',
  description: 'The node js server for shadowsocks server.',
  script: 'C:\\Users\\Developer\\AppData\\Roaming\npm\\node_modules\\shadowsocks\\bin\\ssserver'
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
  svc.start();
});

svc.install();

But when I ran the script with administrator privilege directly, I got the error:

---------------------------
Windows Script Host
---------------------------
Script: C:\src\node-windows\start_service.js
Line:   1
Char:   1
Error:  Object expected
Code:   800A138F
Source:     Microsoft JScript runtime error

---------------------------
OK   
---------------------------

or, I copied the .js to the roaming folder and used node to run the JavaScript, I still got another error:

C:\Users\Developer\AppData\Roaming\npm>node start_service.js
fs.js:747
  return binding.mkdir(pathModule._makeLong(path),
                 ^
Error: ENOENT, no such file or directory 'C:\Users\Developer\AppData\Roaming
pm\node_modules\shadowsocks\bin\daemon'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:747:18)
    at C:\Users\Developer\AppData\Roaming\npm\node_modules\node-windows\lib\daem
on.js:514:16
    at FSReqWrap.cb [as oncomplete] (fs.js:226:19)

I have manually run the ssserver successfully. It can work. I just want to make it as a windows service.

Any help will be much appreciated. thx.

alexya commented 7 years ago

I made a mistake, the file path is wrong

C:\\Users\\Developer\\AppData\\Roaming\npm\\node_modules\\shadowsocks\\bin\\ssserver

it should be

C:\\Users\\Developer\\AppData\\Roaming\\npm\\node_modules\\shadowsocks\\bin\\ssserver