Node.js 'Cannot Get'

Hey, Campers.

I am getting a “Cannot GET” error when I run my node.js application.

Usually that means the resource cannot be found in my folder structure, but I cannot figure out what is wrong with my folder structure to cause this. Or maybe I am asking the wrong question.

Could anybody please point me in the right direction?


Could you post logs for the error you’re experiencing?

from the Chrome console:

Failed to load resource: the server responded with a status of 404 (Not Found) /favicon.ico Failed to load resource: the server responded with a status of 404 (Not Found)


Your code is running at
Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!

Debugger listening on [::]:15454
throw er; // Unhandled ‘error’ event

Error: listen EADDRINUSE :::8080
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at Server._listen2 (net.js:1258:14)
at listen (net.js:1294:10)
at Server.listen (net.js:1390:5)
at (/home/ubuntu/workspace/node_modules/express/lib/application.js:590:24)
at Object. (/home/ubuntu/workspace/server.js:29:5)
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)
at Function.Module._load (module.js:438:3)
at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)

Process exited with code: 1

It means that port 8080 is already in use

How to resolve this?

I tried just using another port.
I made this change:

//var port = process.env.PORT || 8000;
var port = 5000;

in the c9 bash terminal I get:
olddognewtrix123:~/workspace (master) $ node server.js
Node.js listening on port 5000…

but no application actaully runs in the c9 preview or in !

In the debugger I get:

Your code is running at
Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!

Debugger listening on [::]:15454
Node.js listening on port 5000…

Cloud9 assigns the port number I believe.

I run the kill -9 commnd, then reran the application. I am still getting the Error: listen EADDRINUSE :::8080, meaning that port is in use. I have killed all processes, and am still getting this error.

I haven’t used c9 myself so can’t say for sure what the problem is but I did some googling and found many links with solutions. Here is the first link

@olddognewtrix123 try this solution in c9 app running issue. and re-start server again I think this might help to solve your problem.
I had the same issue yesterday but that was rails server solved with this tuts.

I was hoping that would work

I ran Node js server, opened the application, got the ‘Cannot GET’ message, then in another terminal ran

olddognewtrix123:~/workspace (master) $ lsof -i tcp:$PORT
node 23101 ubuntu 12u IPv6 1364250321 0t0 TCP *:http-alt (LISTEN)
olddognewtrix123:~/workspace (master) $ kill -9 PID
bash: kill: PID: arguments must be process or job IDs
olddognewtrix123:~/workspace (master) $ kill -9 23101

then restarted node js server, and still am getting the ‘Cannot GET’ message

So, You mean your server is running but the server routes cannot get into the browser, right? If so your I believe that your routes setting not correct re-watch tuts or re-setup your proper server routes. if you got the message like

Cannot GET /

That means the server could not found your routes. What I know. I’m not NodeJS Expert but I also learning…


I was getting the Error: listen EADDRINUSE :::8080 originally because because I had repeated the app.get function in server.js

Once I corrected things so that the app.get function only shows up in routes/index.js like it is supposed to, I am no longer getting the EADDRINUSE :::8080 message BUT I AM STILL GETTING THE ‘Cannot GET’ message.

So I think it was what I originally expected - the server cannot find the app/routes folder for some reason I have yet to figure out.

Correct, I’d say re-correct your routes folder then you can use the direct router.get middleware. I have used like this

var express = require("express");
var router  = express.Router();

You can read more details about express.router.


And also I think nodeJS doesn’t support direct .html file that needs to register with as a view engine like below my app.js that I using ejs:

app.use(express.static(__dirname + "/public"));
app.use(bodyParser.urlencoded({extended: true}));
app.set("view engine", "ejs");
1 Like

OK, a little chagrinned here.

I just commented out some code

   'use strict';
    var path = process.cwd();

     module.exports = function (app){

     //	var express = require('express');

     	//var app = express();

     app.get('/',function (req, res) {
               res.sendFile(path + '/public/index.html');



and now it seems to be finding my routes folder.

But now there is a NEW error:

TypeError: res.sendFile is not a function
at /home/ubuntu/workspace/app/routes/index.js:31:17
at callbacks (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:164:37)
at param (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:138:11)
at pass (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:173:5)
at Object.router (/home/ubuntu/workspace/node_modules/express/lib/router/index.js:33:10)
at next (/home/ubuntu/workspace/node_modules/connect/lib/proto.js:174:15)
at next (/home/ubuntu/workspace/node_modules/connect/lib/proto.js:149:78)
at next (/home/ubuntu/workspace/node_modules/connect/lib/proto.js:149:78)
at Object.expressInit [as handle] (/home/ubuntu/workspace/node_modules/express/lib/middleware.js:30:5)

This is maddening.

I am beginning to think that despite all the work I have already done (I have built all the microservices required by FCC so far) I really don’t understand some basic node.js functionality.

Is there a tutorial someone can suggest that will really help me figure out what the heck is going on here, specifically with these types of problems? I would be happy to take my time with another good tutorial that explains exactly how to get a complex node.js app to work, if it would help me understand why I am running into all these idiosyncrasies that none of the introductory tutorials seem to cover!.

sendFile function is part of express so of course after you commented express out it’s not gonna work

Ah, of course.

OK, back to ‘Cannot GET /’

@olddognewtrix123 I have not used yet res.sendFile but you can use .ejs plugin instead of .html and set that as a view engine gives the HTML output into browser/client-side.

Do you have any Premium video tuts?
If you want to go through here is a link below 12$ to purchase
FREE links are might already know

  1. Traverse Media youtube channel you can choose a NodeJs videos
  2. MongoDB University - MongoDB for Node.js Developer
  3. You can search plenty of FREE tuts by googling/youtube

What’s in server logs this time?

Just by looking at your code I see that you require ‘express-session’ package but it’s not in package.json dependencies

I must have goofed up something in my last push to git. My sincere apologies!

Here is the most recent code I am using:

1 Like