Matt Cleary Matt Cleary - 1 year ago 68
Javascript Question

Why isn't my Express server reloading?

I'm following along a tutorial, learning Express.

I wrote the following code:

'use strict';

var express = require('express');

var app = express();


Then when I ran the program in the console, and went to my browser (localhost:3000), I simply get the message:
Cannot GET /

Which is to be expected of course.

Next, I'm instructed to update the code to this:

'use strict';

var express = require('express');

var app = express();

app.get('/', function(req, res){
res.send("<h1>I Love Treehouse!</h1>");

app.listen(3000, function(){
console.log("The frontend server is running on port 3000!");

If I kill the server and refresh the page however, I STILL get: `Cannot GET /'

And nothing is logged to the console.

I have killed the process, resaved the program, restarted my text editor and restarted my browser with no success.

Any idea what's happening? I'm following the tutorial line by line and can't see that I've missed anything.

Perhaps there is something out of date?


Answer Source

I work with me... Try :

cd ../

## Create new folder
mkdir testfolder

cd testfolder
## Instal express

npm i express --save
## Create app.js and past your code
nano app.js

## Start app
node app.js