簡體   English   中英

使用 nodejs 應用程序作為 Windows 服務會導致 EPERM-4048 錯誤

[英]Using nodejs app as Windows Service causes EPERM-4048 ERROR

我正在使用“ node-windows ”來創建將在 Windows 上運行我的 app.js 服務器的服務。 這是制作服務的代碼(使用 node-windows 模塊)-

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

// Create a new service object 
var svc = new Service({
  name:'Demo Landing Page',
  description: 'The nodejs.org example web server.',
  script: 'app.js'
});

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

svc.install();

腳本一切正常,但這一行用於讀取目錄內容-

fs.readdir([PATH], function(err, builds)

這是我得到的錯誤 -

{Error: EPERM: operation not permitted, scandir [PATH]
  errno: -4048,
  code: 'EPERM',
  syscall: 'scandir',
  path: 'app.js' }

但如果我不作為服務運行 - 就像 -

node app.js

一切正常,權限很好。

我該怎么做才能解決這個問題? 或者也許還有另一種在 Windows 服務器上運行 nodejs 的選擇?

謝謝!

** 我以管理員身份登錄,並且可以訪問以下目錄

右鍵單擊服務打開其屬性檢查它在登錄下使用的帳戶

要么在上面的代碼中嘗試這個

svc.logOnAs.domain = 'mydomain.local';
svc.logOnAs.account = 'username';
svc.logOnAs.password = 'password';

或者您可以直接添加憑據並重新啟動服務

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM