Failed to torify node application - javascript

I'm writing a simple node server, and trying to torify it. But I got the following error, any idea?
It works fine when I go without torsocks, and I used default config for tor daemon.
$ torsocks node server.js
[Jan 26 09:38:40] WARNING torsocks[30933]: [syscall] Unsupported syscall number 293. Denying the call (in tsocks_syscall() at syscall.c:465)
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EPERM :::5000
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at Server.listen (net.js:1391:5)
at Object.<anonymous> (/home/test/src/heroku/ruten-helper/server.js:10:8)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
var http = require('http')
// Create server
var server = http.createServer(function (req, res) {
console.log("client connected")
res.end('HI!')
})
// Listen
server.listen(process.env.PORT || 5000)

I got it.
I checked the torsocks debug message, I see the following.
[listen] Non localhost inbound connection are not allowed. (in tsocks_listen() at listen.c:64)
And I changed my code to listen on localhost only, problem resolved.

Related

I keep getting an error in my terminal, "error address already in use :::5000"

I'm following a node.js crash course and I get to the part where we are creating a server, but for some reason every time I try to run node index which is my js file name I'm getting the error:
address already in use :::5000
I've looked through similar problems and tried to kill that specific port but nothing seems to work.
if (req.url === '/') {
fs.readFile(
path.join(__dirname, 'public', 'index.html'),
(err, content) => {
if (err) throw err;
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content);
}
);
}
const PORT = process.env.PORT || 5000;
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
node index
node:events:504
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::5000
at Server.setupListenHandle [as _listen2] (node:net:1330:16)
at listenInCluster (node:net:1378:12)
at Server.listen (node:net:1465:7)
at Object.<anonymous> (/Users/zacdistant/Documents/GUIDES AND TUTORIALS/Node JS Crash Course/index.js:91:8)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1357:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -48,
syscall: 'listen',
address: '::',
port: 5000
}
If you are on a Mac, port 5000 and 7000 are already used by the Control Center with the AirPlay reveicer:
lsof -i :5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ControlCe 479 **** 26u IPv4 0xa2d0e96b616f779d 0t0 TCP *:commplex-main (LISTEN)
ControlCe 479 **** 27u IPv6 0xa2d0e96693d0bc65 0t0 TCP *:commplex-main (LISTEN)
To solve the issue you have to either change the port you use in your server like const PORT = process.env.PORT || 9000;, or turn off the AirPlay receiver. Also, if you want to check before hand is the port free, run netstat -anv -p tcp.
As #jamomani explained Mac uses port 5000 and 7000 that are used by the Control Center with the AirPlay receiver
To solve the issue you have to either change the port you use in your server like const PORT = process.env.PORT || 9000;, or turn off the AirPlay receiver. Also, if you want to check before hand is the port free, run netstat -anv -p tcp.

node.js express permission error on linux

using arch with admin user account and no sudo on this script:
var express = require('express');
var fs = require('fs');
var app = express();
app.get('/lol', function(req, res) {
res.sendFile('second.html', {root: __dirname })
});
var port = process.env.PORT || 81;
var server = app.listen(port);
i get this error that didnt change when i changed the port or the url to trigger it
it instantly gives me this error after i run the command: node site.js
(the code above is site.js)
node:events:371
throw er; // Unhandled 'error' event
^
Error: listen EACCES: permission denied 0.0.0.0:81
at Server.setupListenHandle [as _listen2] (node:net:1302:21)
at listenInCluster (node:net:1367:12)
at Server.listen (node:net:1454:7)
at Function.listen (/home/{name}/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/{name}/Documents/web/demo/site.js:10:18)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1346:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EACCES',
errno: -13,
syscall: 'listen',
address: '0.0.0.0',
port: 81
}
if i run the script with sudo it works fine but i dont want to run it in sudo
beacuse i have to run it on a server with no sudo. any help?
Using port below 1024 without root permission is common issue. Try port bigger than 1024.

Getting error while running nodejs code about syntaxerror

I am getting error when i run my node.js code in terminal.I am new to node.js and can't find any solution around internet.
My code:-
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
And error i getting when i run my code in terminal:-
(function (exports, require, module, __filename, __dirname) { {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600
^
SyntaxError: Invalid or unexpected token
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
You need to convert the current file text into plain text format,
go to Format-> Make Plain Text then click on OK button. and then save the file with .js extension.

Node.js Tcp server EACCESS

Using net to create a TCP server on Node.js on a windows machine
var net = require('net');
var host = 'localhost';
var port = '7171';
net.createServer(function(socket) {
console.log('CONNECTED - ' + socket.remoteAddress);
}).listen(host, port);
But Im getting this EACCES error even if I run the node console as admin with control shift click.
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EACCES
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1023:19)
at listen (net.js:1064:10)
at Server.listen (net.js:1132:5)
at Object.<anonymous> (E:\Xampp\htdocs\tibiajs\server.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
Since at windows I normally dont have to deal with these kind of privilegies issues I dont know what to do
You have your params backward:
.listen(host, port);
should be
.listen(port, host);
Also I'd probably pass the port number as a number instead of a string, but either appears to work.
Docs: http://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback
server.listen() takes a port, with optional host. Signature is listen(port, [host], [backlog], [callback]). I think this is what you want:
var net = require('net');
var port = '7171';
net.createServer(function(socket) {
console.log('CONNECTED - ' + socket.remoteAddress);
}).listen(port);

Cannot get my file to display through Node.js

I'm having problems with my node server. I'm trying to gather data from my coffees.js file which is in a routes folder by linking it to my server.js file. Both my server.js file and routes folder containg the coffees.js file are in my nodeservers folder. When I run the server.js (which is probably the problem as I think it is coded wrong) I get the following error:
Server running at http-00000000-:8080/
Listening on port 8080...
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at Function.app.listen (/node_modules/express/lib/application.js:533:24)
at Object.<anonymous> (/home/ec2-user/nodeservers/simpleserver.js:19:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
[ec2-user#ip-10-74-151-139 nodeservers]$ ^C
[ec2-user#ip-10-74-151-139 nodeservers]$
My simpleserver.js file looks like this:
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8080);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8080/");
var express = require('express'),
coffees = require('./routes/coffees');
var app = express();
app.get('/coffees', coffees.findAll);
app.get('/coffees/:id', coffees.findById);
app.listen(8080);
console.log('Listening on port 8080...');
Anyone able to tell me whats wrong?
Remove either
server.listen(8080) or app.listen(8080).
I think you want to use express, so remove the first.

Categories

Resources