vestacp-nodejs icon indicating copy to clipboard operation
vestacp-nodejs copied to clipboard

app.sock not found

Open andersondn opened this issue 4 years ago • 11 comments

Hola amigo!

The file app.sock is not being created, how can I fix this?

andersondn avatar Jun 09 '20 10:06 andersondn

Buenas tardes @andersondn El archivo app.sock es creado por node a momento de intentar conectarse a él. Cuando lo creas debes darle los permisos necesarios para que nginx pueda interactuar con él. Sólo pone la ruta al unix socket en lugar del puerto de conexión, y Node lo creará.

timeignacios avatar Aug 13 '20 20:08 timeignacios

I think this is related to user/ folder permissions. i have made some tests I have made below post (under hestiacp) https://forum.hestiacp.com/t/node-js-support/653/9

beird avatar Sep 02 '20 05:09 beird

Hi there, I was completed all steps. and create a nodejs with express ejs basic app. and I just directly uploaded the file into my vesta's website directory. If I hit the domain, I got 500 error. also, I don't have the .sock file. can you please explain the .sock part only. how to create the .sock file or what we need to do in our node app.

Thanks, Karthikeyan

iamkbkarthikeyan avatar Sep 24 '20 17:09 iamkbkarthikeyan

@iamkbkarthikeyan If you put a listen like this: http.listen('app.sock', callback); Node will create the app.sock file for you.

Maybe you need some extra code for service restart cases, because the socket file needs to be removed and re-created for every NodeJS restart.

The following code detects errors when creating the server. Delete and recreate the socket file

  http.on('error', function (e) {
    if (e.code == 'EADDRINUSE') {
        var clientSocket = new net.Socket();
        clientSocket.on('error', function(e) { // handle error trying to talk to server
            if (e.code == 'ECONNREFUSED') {  // No other server listening
                fs.unlinkSync('app.sock');
                http.listen('app.sock', callback);
            }
        });
        clientSocket.connect({path: 'app.sock'}, function() { 
            console.log('Server running, giving up...');
            process.exit();
        });
    }
  });

Good luck !!

nchsala avatar Sep 24 '20 21:09 nchsala

So, we can't use express.js instead of express we're using http server right? or is there any possibility to run express app.

iamkbkarthikeyan avatar Sep 25 '20 08:09 iamkbkarthikeyan

@iamkbkarthikeyan With something like

const express = require('express');
const app = express();
const http = require('http').Server(app);

You can use the express app object and all the http events without problems

nchsala avatar Sep 25 '20 10:09 nchsala

Hi, can you please create a simple node app for demonstration and push into git repo. Also attach the link into this repo's readme file. It might helpful for everyone. Still I can't deploy it. Getting same errors.

Thanks, Karthikeyan

iamkbkarthikeyan avatar Sep 30 '20 23:09 iamkbkarthikeyan

In our example you can use express like that;

const express = require('express')
const app = express()
const port = '/home/admin/web/YOUR_DOMAIN.COM/nodeapp/app.sock';
const hostname = 'YOUR_HOST_NAME';

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.get('/about', (req, res) => {
  res.send({ info: 'APP test server'  });
})

app.listen(port, hostname, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

Then run this command;

pm2 start app.js

Don't forget to chmod 777 "$(pwd)/app.sock" command after started server.

I have a bash script like that;

/home/admin/web/YOUR_DOMAIN.COM/nodeapp/server.sh

rm -f "$(pwd)/app.sock"
pm2 start app.js
echo "Starting server..."
sleep 2
chmod 777 "$(pwd)/app.sock"
echo "Server started..."

aligoren avatar Oct 20 '20 08:10 aligoren

In our example you can use express like that;

const express = require('express')
const app = express()
const port = '/home/admin/web/YOUR_DOMAIN.COM/nodeapp/app.sock';
const hostname = 'YOUR_HOST_NAME';

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.get('/about', (req, res) => {
  res.send({ info: 'APP test server'  });
})

app.listen(port, hostname, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

Then run this command;

pm2 start app.js

Don't forget to chmod 777 "$(pwd)/app.sock" command after started server.

I have a bash script like that;

/home/admin/web/YOUR_DOMAIN.COM/nodeapp/server.sh

rm -f "$(pwd)/app.sock"
pm2 start app.js
echo "Starting server..."
sleep 2
chmod 777 "$(pwd)/app.sock"
echo "Server started..."

hello, i want to ask, for hostname, we put public ip address or 127.0.0.1 localhost ? thanks

ryanspandu avatar Oct 21 '20 03:10 ryanspandu

In our example you can use express like that;

const express = require('express')
const app = express()
const port = '/home/admin/web/YOUR_DOMAIN.COM/nodeapp/app.sock';
const hostname = 'YOUR_HOST_NAME';

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.get('/about', (req, res) => {
  res.send({ info: 'APP test server'  });
})

app.listen(port, hostname, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

Then run this command;

pm2 start app.js

Don't forget to chmod 777 "$(pwd)/app.sock" command after started server. I have a bash script like that; /home/admin/web/YOUR_DOMAIN.COM/nodeapp/server.sh

rm -f "$(pwd)/app.sock"
pm2 start app.js
echo "Starting server..."
sleep 2
chmod 777 "$(pwd)/app.sock"
echo "Server started..."

hello, i want to ask, for hostname, we put public ip address or 127.0.0.1 localhost ? thanks

I put a public IP address. I didn't try it with a local address. But I think it should work both ways.

aligoren avatar Oct 21 '20 06:10 aligoren

I have some problem, if I use bash server.sh the error is connection refused

hisamaszaini avatar Aug 11 '21 23:08 hisamaszaini