Node.js “如何修复”;xinit:无法连接到X服务器;在nodejsexec中

Node.js “如何修复”;xinit:无法连接到X服务器;在nodejsexec中,node.js,linux,xserver,Node.js,Linux,Xserver,我的Xserver不是从nodejs脚本启动的。我必须以root用户身份运行它,否则会发生以下错误: /usr/lib/xorg/xorg.wrap:只允许控制台用户运行X服务器 因此,我以 sudo node controller.js 首先,我启动控制器运行一个区域设置Web服务器。然后,我想启动Xorg服务器,并按照xinit命令运行chromium浏览器 const http = require('http'); const fs = require('fs'); const path

我的Xserver不是从nodejs脚本启动的。我必须以root用户身份运行它,否则会发生以下错误:

/usr/lib/xorg/xorg.wrap:只允许控制台用户运行X服务器

因此,我以

sudo node controller.js

首先,我启动控制器运行一个区域设置Web服务器。然后,我想启动Xorg服务器,并按照xinit命令运行chromium浏览器

const http = require('http');
const fs = require('fs');
const path = require('path');
const config = require('./config.json');
const shell = require('shelljs');

http.createServer(function (request, response) {
    var filePath = '.' + request.url;
    if(filePath == './'){
        filePath = config.baseFile;
    }
    var extname = path.extname(filePath);
    var contentType='text/html';
    switch(extname){
        case '.js':
            contentType = 'text/javascript';
            break;
        case '.css':
            contentType = 'text/css';
            break;
        case '.json':
            contentType = 'application/json';
            break;
        case '.png':
            contentType = 'image/png';
            break;      
        case '.jpg':
            contentType = 'image/jpg';
            break;
        case '.wav':
            contentType = 'audio/wav';
            break;
    }
    fs.readFile(filePath, function(error, content) {
        if (error) {
            if(error.code == 'ENOENT'){
                fs.readFile('./404.html', function(error, content) {
                    response.writeHead(200, { 'Content-Type': contentType });
                    response.end(content, 'utf-8');
                });
            }
            else {
                response.writeHead(500);
                response.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
                response.end(); 
            }
        }
        else {
            response.writeHead(200, { 'Content-Type': contentType });
            response.end(content, 'utf-8');
        }
    });
}).listen(8080);
console.log('Server running at http://127.0.0.1:8080/');
shell.exec('xinit chromium-browser --start-maximized -kiosk http://localhost:8080/');
(EE)
致命的服务器错误:
(EE)服务器已为处于活动状态 显示0
如果此服务器不再运行,请删除 /tmp/.X0锁定并重新启动。
(EE)
(EE)
请咨询 X.org基金会支持寻求帮助。 (EE)
未指定协议
xinit:放弃
xinit:无法 要连接到X服务器:资源暂时不可用
xinit: 服务器错误

我多次删除了这个文件。我使用树莓拉伸版发行版

$ps auxw | grep X
pi 949 0.0 0.0 3536 624 tty1 S+16:38 0:00 xinit/etc/X11/xinit/xinitrc--/etc/X11/xinit/xserverrc:0 vt1-keepty-auth/tmp/serverauth.wsn7HgMgWE
root 949 0.0 3.9 182112 37440 tty1 S1 16:38 0:00/usr/lib/xorg/xorg-nolisten tcp:0 vt1-keepty-auth/tmp/serverauth.wsn7HgMgWE
pi 11880.0 0.0 4772 572 tty5 R+17:18 0:00 grep--color=auto X