irom
irom

Reputation: 3606

nodejs echo to localhost unix socket

I would like to have NodeJS API to be able to communicate with program (not wirtten by myself) which listens on localhost Unix socket 5050. I can 'echo' from shell to Unix socket 5050 where this program listens

$echo '{"output": "connecting"}' > /dev/tcp/localhost/5050

Now, for external programs to write to this localhost socket I need API, don't know how to do it:

app.post('/output', function (req, res) {    
    //echo '{"output": "connecting"}' > /dev/tcp/localhost/5050

});

Upvotes: 0

Views: 122

Answers (1)

mscdex
mscdex

Reputation: 106706

You can connect to the unix socket via the same net.connect(). From there it's just a matter of writing to the socket (socket.write()) once the callback is called.

Upvotes: 1

Related Questions