I'm having an issue where reloading (ctrl + c and then running again with node app) a basic Node.js server (tried v0.12.0 and v0.12.7) on Windows 10 causes the server to hang for about 20 seconds before reloading. When using a tool like PM2 to watch my server, it errors out after any update to the file and the log shows an EADDRINUSE error.
I boiled this down to the most simple possible example (thinking it might be an issue with Express) but it's still happening with the basic example from the Node.js documentation:
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3030);
console.log('Server running at http://127.0.0.1:3030/');
I've checked that nothing else is running on port 3030. I've also tried different port numbers. It just seems that the Node.js process is not shutting down and releasing the port in a timely manner. I've also tried using ctrl+break, and also capturing the SIGINT and manually calling process.exit(). I can confirm that it catches the signal, but it still hangs as described.
I first noticed this shortly after upgrading to Windows 10 from 7, and was not having issues before, so I would think this is the most likely culprit. I have a dual-boot with Ubuntu 14.04, and I am having no issues there with the same code.
I'm no longer having the problem I described: it was likely something very specific to my setup since it wasn't reported anywhere else. I have since updated to Node 4.2.1 and installed various Windows updates, so hard to say what the original cause was.
Related
Have this setup:
expressjs server started from one node process, listening to port 8081.
js client trying to make a request to it from another node process, using node's http module.
client failing with 400 error.
same URL (http://localhost:8081/) is opening in browser just fine.
Spent a few hours trying to troubleshoot it, then tried to change the port and it worked.
Turns out there is another process listening on port 8081:
$ lsof -i tcp:8081
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
EUSAManag 1187 oleksandr.suhak 4u IPv4 0xce3bb9546cff3ab1 0t0 TCP localhost:sunproxyadmin (LISTEN)
(Have no idea what EUSAManag is)
I guess my question is: how could it be that the express server starts fine without complaining to a "port being used by another process" when the port is clearly in use. And why does it work then when accessing it from the browser, but does not work when making request from js client? Any tips on figuring out what is actually happening here?
If guess that EUSAManager.exe come from one of software https://iit.com.ua/downloads which is in the business of information security. Most likely their software interfere too much with you operation system.
Why does my localhost:3000 application take so long to load? I have tried quite a lot of ways to solve this, such as:
Disable IPv6
Add localhost into the hosts file
Update npm and node.js to the latest version
The localhost doesn't load, and eventually, just stops loading and refuses to connect. I don't know why this is happening. I am using Microsoft Edge and Windows 10.
Here is my code:
//jshint esversion:6
const express = require("express");
const app = express();
app.get("/", function(request, response) {
response.send("Hello World");
});
app.listen(3000, function()
{
console.log("Server is listening on port 3000.");
});
Any Help would be appreciated. Thanks.
Edit: It used to load at least a little bit but never fully loaded, now it just refuses to connect. :(
The command line exited the node application, but from my side, it said it was still running. It must have just been a bug. I restarted my pc and it worked.
I'm new into node JS. I'm trying to install node and run just a 'Hello World' app but I have problems with my server.
When I try to run my app, the server is showing only the index files and not 'Hello World'. enter image description here
The node server is working and says that the http-server is available.
My code for my Hello World app:
var http = require("http");
http.createServer(function(req, res){
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8080);
console.log('Server running at http://192.168.178.14:8080/');
I want to run the file 'index.js' (second file in first screenshot). How can I fix this?
As Mikael Lennholm and robertklep have mentioned in the comments, the issue is that you are trying to run a second server on the same address (:8080).
I tested this myself to make sure, and here's the results I got:
Running an instance of the ecstatic server on :8080, producing a very similar image to yours (using default code provided by ecstatic's documentation).
Attempting to run a regular server on the :8080 port gives me an error, EADDRINUSE :::8080 (which is expected, as the other application is already using that address). You should probably get this error when trying to run your application as well.
Now, either you or someone else is to blame. But the fact is that there is already a server running on port 8080. I'd reccomend you try to find out who set it up (if it wasn't yourself) or maybe just try using another port. For example, 8088:
With my current web development practices, I always run my code (html, css, javascript) on an internet browser.
I'm trying to learn Node.js, and all the tutorials are using command line to run the node.js files.
My problem is, I don't know how to use terminal for development purposes (I've never really used it at all)
Why would I even be running a website on a terminal window rather than a browser where it should be run?
And lastly, can I run node.js code on a web browser, similar to how I run my javascript files? Or do i HAVE TO run Node.js on a terminal window if I want to test it or something?
This content shows 3 basic steps:
Step 1 Install Node.js
Step 2 Use an editor to write some JavaScript
Step 3 Run the application "node appName.js" and a browser to test "host-ip:port" ex: http://127.0.0.1:3000
source code
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');
I am using Cloud 9 IDE to develop a simple CRUD application using Sails.js (node.js MVC framework). Up until today I had no trouble starting the Sails.js server.
Today, I've been trying to start the sails js server, but I keep getting this error:
warn: error raised: Error: listen EACCES
error: Server doesn't seem to be starting.
error: Perhaps something else is already running on port 8080?
I have checked my /config/local.js file and everything is just fine, as it should be. The port is set to process.env.PORT || 1337 so it shouldn't have any problems firing the server up.
I'm looking forward to your insight.
Thank you!
Open terminal and run this command:
$ lsof -i :8080
Output will show PID of process occupying port 8080: "httpd 1234 ....'
Then kill the process with this command
$ kill -9 1234
Sails will now run
Hmm-- looks like port 8080 isn't available. What happens if you try to switch the port? You may have another server running on that port. Or in some cases, hosts require the hostname to be set. I'd try switching the port first though.
The only real answer to this is: wait. C9 seems to kill servers in a weird way that causes Sails to jack up and blocks you from establishing another server. lsof -i doesn't show anything serving... but it still won't start. Seems to be an issue with Cloud 9 and Sails.js. If I serve a generic Node.js "Hello World" app on the same port, the issue doesn't occur. However, time, it seems, cures all. After awhile, Sails seems to snap out of it and starts serving again when lifted.
Incredibly weird.