I have a POST function in which I am trying to start VLC player using the child_process. I am using the latest Raspbian version.
router.post('/', function (req, res) {
let spawn = require('child_process').spawn;
let vlc = spawn('vlc');
vlc.stderr.on('data', function(data) {
console.log(data.toString());
});
vlc.on('exit', function(code){
console.log('Exit code: ' + code);
});
res.send({success: true})
});
After triggering the request, I get this message:
VLC is not supposed to be run as root. Sorry. If you need to use
real-time priorities and/or privileged TCP ports you can use
vlc-wrapper (make sure it is Set-UID root and cannot be run by
non-trusted users first).
Since VLC cannot be run as root, I added the UID argument to the vlc start script, and it now looks like this:
let vlc = spawn('vlc' ,{uid: 1000});
Where UID: 1000 is the ID of the user I always use.
After triggering the request, I get another message in the log:
[016f9960] main libvlc error: cannot open config file
(/root/.config/vlc/vlcrc): Permission denied
Home directory not accessible: Permission denied
[01762eb0] vlcpulse audio output error: PulseAudio server connection
failure: Connection refused
[0176bde8] dbus interface error: Failed to connect to the D-Bus
session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY
for X11
[0176bde8] main interface error: no suitable interface module
[016f9960] main libvlc error: interface "dbus,none" initialization
failed
[0176c7a8] main interface error: no suitable interface module
[016f9960] main libvlc error: interface "globalhotkeys,none"
initialization failed
[016f9960] main libvlc: Running vlc with the default interface. Use
'cvlc' to use vlc without interface.
error: XDG_RUNTIME_DIR not set in the environment.
[0176c7a8] skins2 interface error: cannot initialize OSFactory
[017614e0] main playlist: playlist is empty
[0176c7a8] [cli] lua interface: Listening on host "*console".
The player doesn't run. But if I run the same command via ssh, it will run. What could cause node from not running it?
The problem was that my server was running using
nodemon
I literally tried everything, and then when I was about to give up, I accidentally started server the normal way using node command. The VLC is starting without any errors. I didn't have to pass any user ID in arguments. It works fine just like this:
let spawn = require('child_process').spawn;
let vlc = spawn('vlc');
I'm really curious why nodemon could cause such a behaviour.
Related
megerr when launching chrome in headlless mode :
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
I'm writing a script node express,
when express receive a http request,
the script node launch new chrome instance in headless-mode using lib chrome_launcher ,
do some stuff,
and kill the istance.
the remote server is a VPS with ubuntu16.04.
to launch the webserver I connect via ssh with VPS:
$ node app_ws.js &
If the ssh connection is alive all works fine and node script can launch chrome regularly.
Instead, when I close the terminal and break-down the ssh connection (and the user session terminates) then starts the badly:
in the first request chrome is launched, OK,
from the second request onwards script cant launch chrome, the message error is:
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
code snippets
//launch chrome in hadless mode using npm lib chrome_launcher (https://github.com/cyrus-and/chrome-remote-interface)
const chrome = await chromeLauncher.launch({
"chromeFlags": [ '--disable-gpu', '--headless' ]
});
//Kill Chrome
chrome.kill()
chrome.kill() return a promise but dont catch any error
thanks from now for help
Requirement is to fetch the output of a shell script's after running it from the Angular 4 component at the beginning during compilation i.e. just before the website is launched. I have already gone through the threads in stackoverflow i.e. 49700941 and 41637166.
From the first thread i tried to use the below code, but getting error:
Module not found: Error: Can't resolve 'child_process' in 'app/component ...'
const exec = require('child_process').exec; // Can't resolve 'child_process' error coming from this line
exec('/home/myDir/init_setup.sh', (err, stdout, stderr) => {
if (err){
console.error(err);
return;
};
console.log(stdout);
console.log(stderr);
/**
remaining logics
*/
});
Please let me know if I need to import some library explicitly or not to avoid this error.
The modern browsers opens the webpage in isolated sandbox so they have have no access to clients' computers.
Imagine the damage that could be done if a black hat could run batch script on computer that opens his webpage.
The only way to run the script is to run the desktop application on client's machine.
The example code you provided is Node.js code, the desktop framework that user have to install on his machine and run the code intentionally. There's (fortunately!) no way to run it remotely via webpage.
Basically, my requirement is to keep looking for new files in the folder, read the contents of the file and call the loopback API.
To achieve that I am trying to do something like below:
I have a remote method in loopback which needs to be called periodically i.e. after every 2 minutes. I read about the asynchronous boot scripts in the official loopback documentation here:
https://loopback.io/doc/en/lb2/Defining-boot-scripts#synchronous-and-asynchronous-boot-scripts
So far I have been able to write the following code:
module.exports = function(app, callback) {
setInterval(function() {
console.log('Hello world');
callback();
}, 120000);
};
But this throws an error below.
error: uncaughtException: listen EADDRINUSE :::443
Also, is there a way to call remote methods from the bootscripts ? Does loopback support cron/schedular or polling like functionality. Do I need to write a separate nodejs application which will call the API periodically.
Thanks
Your error states that your address(port number) if the server is already in use.
error: uncaughtException: listen EADDRINUSE :::443
You can try to listen on some other port number
app.listen(3000, function() {
console.log('listening on 3000')
});
Kill process running on same port
First, you would want to know which process is using port 3000
sudo lsof -i :3000
this will list all PID listening on this port, once you have the PID you can terminate it with the following:
kill -9 {PID}
Check if your code is not calling multiple listen on the same port
Let me know if this isn't resolving your problem
I'm new to Node.js and wish to run a program using streams. With other programs, I had to start a server simultaneously (mongodb, redis, etc) but I have no idea if I'm supposed to run one with this. Please let me know where I am going wrong and how I can rectify this.
This is the program:
var http = require('http'),
feed = 'http://isaacs.iriscouch.com/registry/_changes?feed=continuous';
function decide(cb) {
setTimeout(function () {
if (Date.now()%2) { return console.log('rejected'); }
cb();
}, 2000);
}
http.get(feed, function (res) {
decide(res.pipe.bind(res, process.stdout));
//using anonymous function instead of bind:
// decide(function () {
// res.pipe(process.stdout)
// });
});
This is the cmd output:
<b>C:\05-Employing Streams\05-Employing Streams\23-Playing with pipes>node npm_stre
am_piper.js
events.js:72
throw er; // Unhandled 'error' event
^
Error: Parse Error
at Socket.socketOnData (http.js:1583:20)
at TCP.onread (net.js:527:27)
</b>
Close nodejs app running in another shell.
Restart the terminal and run the program again.
Another server might be also using the same port that you have used for nodejs. Kill the process that is using nodejs port and run the app.
To find the PID of the application that is using port:8000
$ fuser 8000/tcp
8000/tcp: 16708
Here PID is 16708 Now kill the process using the kill [PID] command
$ kill 16708
I had the same problem. I closed terminal and restarted node. This worked for me.
Well, your script throws an error and you just need to catch it (and/or prevent it from happening). I had the same error, for me it was an already used port (EADDRINUSE).
I always do the following whenever I get such error:
// remove node_modules/
rm -rf node_modules/
// install node_modules/ again
npm install // or, yarn
and then start the project
npm start //or, yarn start
It works fine after re-installing node_modules. But I don't know if it's good practice.
Check your terminal it happen only when you have your application running on another terminal..
The port is already listening..
For what is worth, I got this error doing a clean install of nodejs and npm packages of my current linux-distribution
I've installed meteor using
npm install metor
And got the above referenced error. After wasting some time, I found out I should have used meteor's way to update itself:
meteor update
This command output, among others, the message that meteor was severely outdated (over 2 years) and that it was going to install itself using:
curl https://install.meteor.com/ | sh
Which was probably the command I should have run in the first place.
So the solution might be to upgrade/update whatever nodejs package(js) you're using.
I am very new to node.js, I just followed the steps to create a simple node.js application. Here it is on github
I ran the command jitsu deploy from the terminal to deploy it on nodejitsu, however I got this error right here, please any help on what could be wrong with code files?
Here is the code on git hub
Here is the error that is appearing:
prompt: Is this ok?: (yes) yes
info: Creating snapshot 0.0.0-5
info Uploading: [=============================] 100%
info: Updating app test
info: Activating snapshot 0.0.0-5 for test
info: Starting app test
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy the app
error:
error: Error spawning drone
error: Script took too long to listen on a socket
error:
error: This type of error is usually a user error.
error: Error output from Haibu:
error:
error: Error: Error spawning drone
error: at Object.onTimeout [as _onTimeout] (/root/haibu-orchestra/node_mod
ules/haibu/lib/haibu/core/spawner.js:396:15)
error: at Timer.list.ontimeout (timers.js:101:19)
help: For help with this error contact Nodejitsu Support:
help: webchat: <http://webchat.nodejitsu.com/>
help: irc: <irc://chat.freenode.net/#nodejitsu>
help: email: <support#nodejitsu.com>
You're server.js is exporting a function, but that doesn't get run. Just the body of your start function as top-level code directly inside the server.js module so that it executes when nodejitsu starts your application.
Nodejitsu is very picky about how quick your deployments listen on the system. There is a certain time frame between the start of deployment and end of deployment before your deployment is considered a failure. When it doesn't listen on a port for so long, it ends up giving you this error.
Rather than using your current start function, why don't you try creating your HTTP socket in index.js and then passing it into your start function as well, since you're already passing routes and handle to it?
For example, in index.js:
var http = require('http'),
server = http.createServer().listen(8080);
start(server, router.route, handle);
Then, rather than using http.createServer(onRequest).listen(8080) in your server.js file, you can use something like:
var start = function (server, route, handle) {
function onRequest(request, response) {
/* Your request stuff here */
}
server.on('request', onRequest);
};
This would most likely solve the whole problem.