Jump to content

Why my Node.js script went wrong on Tommy?


Recommended Posts

Posted

Following two app.js both run fine on my local computer. But when I upload them to Tommy, the first script went wrong while the second is OK. So I wonder what could cause this? They seem to do the same thing.

(1) app.js using net

var net = require("net");

var server = net.createServer(function (socket) {
    socket.on("data", function (data) {
        let resp = "HTTP/1.0 200 OK\r\n" +
            "Content-Type: text/html\r\n" +
            "Content-Length: 10\r\n" +
            "\r\nIt works!!";
        socket.write(resp);
    });
});

server.listen(3000, '127.0.0.1', function () {
    console.log("listening on port 3000");
});

(2) app.js using http

const http = require('http');

const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/html');
    res.end(`Node.js works!`);
});

server.listen(3000, '127.0.0.1', () => {
    console.log("listening on port 3000");
});

 

Posted
On 11/23/2022 at 4:40 PM, Krydos said:

What did it say in the logs for option #1?

Error ID:

9867a925

Details:

Web application could not be started by the Phusion Passenger(R) application server.

Please read the Passenger log file (search for the Error ID) to find the details of the error.

 

I look into the logs and find "App 8492 output: Error: listen EADDRINUSE: address already in use 127.0.0.1:3000"

But both scripts listen on that address and port, #2 runs without errors.

Posted
6 hours ago, Krydos said:

Did you try another port such as 3001 with code option #1?

Using port 3000:

Quote

15549/T2h age/Cor/App/Implementation.cpp:221: Could not spawn process for application /home/rus.helioho.st/httpdocs: The application process exited prematurely.
Error ID: 525ad134
Error details saved to: /tmp/passenger-error-cpo06h.html

App 116961 output: 116961/T1 age/Spa/SpawnEnvSetupperMain.cpp:747: shellName = 'false' detected as supporting '-l': false
App 116961 output: node:events:491
App 116961 output: throw er; // Unhandled 'error' event
App 116961 output: ^
App 116961 output:
App 116961 output: Error: listen EADDRINUSE: address already in use :::3000

 

Using port 3001:
 

Quote

 

105131#0: *20020 upstream timed out (110: Connection timed out) while reading response header from upstream

100376/Ty age/Cor/App/Implementation.cpp:221: Could not spawn process for application /home/rus.helioho.st/httpdocs: A timeout occurred while spawning an application process.
Error ID: 88f54452
Error details saved to: /tmp/passenger-error-EWUMQ7.html

App 97403 output: 97403/T1 age/Spa/SpawnEnvSetupperMain.cpp:747: shellName = 'false' detected as supporting '-l': false
App 97403 output: listening on port 3001

 

So I guess Passenger just don't work with such toy scripts. Maybe if some http server capabilities is checked during startup, my script #1 "exited prematurely.

Thanks:)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...