Nodejs HTTP Request ERRCONNREFUSED - javascript

I am trying to start building node apps and having trouble with my instance.
After working with require('http').get(...) for some time and having no success, I decided to try the example from the API docs as follows.
var http=require('http')
http.get("http://www.google.com/index.html", function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
http.get api, Nodejs.org
and for every single time that I have tried I receive an error saying ECONNREFUSED
More detailed error object below;
Got error:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
`
I really don't know why this is and I get the same error message for every single host I try, even localhost/127.0.0.1, www.google.com, www.example.com
uname -a
Linux localhost 3.10.18 #1 SMP Fri Mar 20 20:43:59 PDT 2015 x86_64 x86_64 x86_64 GNU/Linux
node -v
v0.6.12
npm -v
1.1.4

After updating my Node to a more recent version I can use require('http').get(...) successfully.

Related

"spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell ENOENT" error while running npm start

When ever I try to execute npm start, this is what happens. I think there is some issue with powershell and not with npm because npm starts the development server. BTW I created basic react app using npx create-react-app. I checked, powershell file is there in the specified location and it is working as well. Guild me what should I do in order to resolve the error.
events.js:353
throw er; // Unhandled 'error' event
^
Error: spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell',
path: 'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell',
spawnargs: [
'-NoProfile',
'-NonInteractive',
'–ExecutionPolicy',
'Bypass',
'-EncodedCommand',
'UwB0AGEAcgB0ACAAIgBoAHQAdABwADoALwAvAGwAbwBjAGEAbABoAG8AcwB0ADoAMwAwADAAMAAiAA=='
]
}
I faced with a same problem on Windows 10.
And solution was a pretty simple - just run your commands in git bush console.
Step 1:(reason of the error)
go to C:\Windows\System32\WindowsPowerShell\v1.0 and then you will not be found powershell.exe file that folder.
Step 2: (solution of the error)
download powershell.exe file online or just copy and paste this file in C:\Windows\System32\WindowsPowerShell\v1.0
https://www.exefiles.com/en/exe/powershell-exe/ - To download powershell.exe file online
So after trying everything and looking for the error on every possible website. I still wasn't able to resolve the error. Then I personally talked to someone regarding the error and he suggested me to run it in Windows Sub-system for Linux (WSL). I exactly did that and installed WSL with Linux 20.04 LTS. Now I am using Unix terminal to create the react app. It isn't the best solution for the problem, but yeah it does work and saves a lot of time!

ECONNREFUSED on running localhost server from NodeJS

I have a NodeJS server up and running on my local machine that is listening to port 50000.
From another server, that is also running on my local machine, I need to make a simple GET request to that server, but all I get is an ECONNREFUSED error:
{ Error: connect ECONNREFUSED 127.0.0.1:50000
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 50000 }
My request looks as follows, using request:
var options = {
url: "http://localhost:50000",
method: "GET"
}
request(options, function(error, response, body) {
if (error) {
console.log("[" + getDateTime() + "] Error connecting to localhost:");
console.log(error);
return;
}
// continue ...
I know that the server is up and running and that the endpoint is defined, because I can do the request to that exact same url in postman or in my browser and get a response, but somehow not in my NodeJS code.
Anybody have an idea?
The possible issue is that some else process is already running on the same port you are trying to use, either change your port or kill the existing process on your port. To kill the process on port you can try:
For mac:
sudo kill $(lsof -t -i:8000)
# or
sudo fuser -k -n tcp 8000
# or
fuser -k 8000/tcp
And for windows check this
hope this helps :)
You might be running both the servers on the same port, kill another server on same port.
If you're on linux, you can kill port using sudo fuser -k -n tcp 5000
or if you're using windows: taskkill /PID 5000 /F
Just as commented, changing "localhost" to "http://127.0.01:50000" worked for me.
I ll leave a link down here for a possible explanation for this issue
https://github.com/node-fetch/node-fetch/issues/1624#issuecomment-1235826631

Error when launching server.js on Ethereum Hello World app

I followed this tutorial with the web3 1.0 source code.
The tutorial suggested to use web3 0.20.x but web3 0.20.x could not be installed in my computer(Ubuntu 16.04.3).
https://medium.com/#mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2
https://github.com/mjhm/hello_world_dapp
I installed and downloaded necessary files and ganache-cli is launched successfully.
Listening on localhost:8545
eth_accounts
eth_gasPrice
eth_sendTransaction
Transaction: 0xffcd7597522313760d262b251037024002054f66fa354892fe65955510f0049c
Contract created: 0x91885fa1a0644951b43ddb57d8d50c441fee26c6
Gas usage: 354524
Block Number: 1
Block Time: Tue Dec 26 2017 06:23:23 GMT+0000 (UTC)
eth_getTransactionReceipt
eth_getCode
Now I want to launch http_server with npm run http_server command but I got error:
> hello_world_voting#1.0.0 http_server /home/g-iot-info/hello_world_voting
> ./server.js
Unhandled rejection Error: Provider not set or invalid
How do I solve this problem?
I don't know where I should look at first.
Thanks in advance.

How to run openshift MEAN project in localhost or development system Ubuntu?

I have created a MEAN stack application on https://openshift.redhat.com/ and it was successfully running on the web.
Default source code of the project synced form: https://github.com/linnovate/mean-on-openshift.git
For further development I am cloning the hosted git source using using git url mentioned in the applications page. (e.g git clone ssh://55e86e9f89f5cf1d29000001#nodejs-tapslab.rhcloud.com/~/git/nodejs.git/).
After clone the source code to local system, opening the project in sublime text editor. I can see in the config/env/development.js there are lot of configuration are used like process.env.OPENSHIFT_XXX. I was changed the some config value mentioned below and trying to start server using command : 'node server', but server was not starting throwing error.
{
db: db: 'mongodb://' + (process.env.DB_PORT_27017_TCP_ADDR || 'localhost:27017') + ':' + '/mean-dev',
hostname: process.env.OPENSHIFT_NODEJS_IP || 'http://localhost:3000'
}
Can someone help me how to run Openshift mean project in local system and what all configuration needed before running it in local system.
System Config :
Ubuntu 12.04
MongoDB v2.6.6
Nodejs v0.10.40
npm 1.4.28
grunt-cli v0.1.13
Error :
$ node server
Mean app started on port 3000 (development)
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Git:
$ NODE_ENV=test node server

Error starting a test with testacular

I am trying out the angularjs tutorials on a 64 bit Windows 7 system because I find this framework quite interesting from what I read on its home page. I am a newbie to node.js and not experienced in Java-Script.
When running the tests, I get the following error. Can anybody find out what the problem is or give some hints how to determine that? I have a fresh Installation of node and added testacular with
npm install -g testacular
which worked fine from what was printed on the console window.
So here is the error message:
PS C:\Users\xx\Documents\Angular\angular-phonecat> .\scripts\test.bat
INFO [testacular]: Testacular server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
ERROR [testacular]: { [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }
Error: spawn ENOENT
at errnoException (child_process.js:948:11)
at Process.ChildProcess._handle.onexit (child_process.js:739:34)
Short answer:
Set env variable CHROME_BIN to full path to chrome.exe
The error msg is confusing, as the behavior of spawn got changed in Node 0.10, we need to update it (https://github.com/karma-runner/karma/issues/452)
Inserting 'PhantomJS' for the test browser in the karma configuration file on Windows Vista resulted in the same error message: { [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }
I ad-libbed on the advice above and inserted in the system path ("Environmental Variables") under "User variables for owner" PHANTOMJS_BIN with the value consisting of the path including phantomjs.exe (C:\Program Files\phantomjs-1.9.0-windows\phantomjs.exe)
All good, jasmine angularjs tests running now and much faster than with 'Chrome' or 'Firefox' as the test browser.

Categories

Resources