0

I ran a php script on the localhost with chrome to execute the following node.js file, named test2.js:

var express = require("express");
var app = express();
var notams = require("notams");

app.get("/", function(req, resp){
notams(['LMMM', 'LMML'], { format: 'DOMESTIC' }).then(results => {
    resp.end(JSON.stringify(results));
});
});

    app.listen(1000, function (){
    console.log("Listening on Port 1337");
});

The php script used was the following:

<?php
echo shell_exec("node test2.js 2>&1");
?>

It worked well. The only thing that did not display is the console.log msg on the browser console. (Any reason why?)

My main problem was that when I changed the script to listen on another port, the previous port (1000) was still being used by the node, even after restarting the pc and closing the browser. How can I clear up the ports from the node? P.S.I'm running on Windows 10.

Vanny
  • 11
  • 7
  • _"The only thing that did not display is the console.log msg on the browser console. (Any reason why?)"_ - this will never show in the browser console, because it is ran on the server – codtex Feb 28 '18 at 10:13
  • Any way how to see it then? Is there a way to see the logs ran on the server? – Vanny Feb 28 '18 at 10:59

2 Answers2

0
  1. Open the cmd in Administration mode.
  2. Punch in netstat -a -b
  3. Checkout who uses your port
  4. taskkill /f /im [pid of the port 1000 got from previous command]

Hope it helps.

Adrian Madaras
  • 347
  • 3
  • 13
  • Thanks. It worked. Now, is there a way to do the same thing with php code? I want this php to run on a live website when a particular page loads, the result from the node gets extracted and the port then vacated. – Vanny Feb 28 '18 at 10:50
  • I think this topic is covered in a different post: https://stackoverflow.com/questions/11209509/using-php-to-execute-cmd-commands. Have a look. – Adrian Madaras Feb 28 '18 at 12:06
0

In node.js console.log() will display log in cmd not in browser

Maulik
  • 104
  • 7