Basic Node and Express - Start a Working Express Server

Basic Node and Express - Start a Working Express Server
0

#1

Does anyone know how to get pass this lesson?, i have created myApp.js file in glitch, put inside this code.:

var express = require (“express”);
var app = express();

app.get("/", function(req, res) {
res.send(‘Hello Express’);
});

//on port 3000 it was throwing error, on 3001 the error is gone but i cannot get anything and it doesnt work on localhost:3001/

app.listen(3001, function() {
console.log(‘Listening on port 3000’);
});

Got stuck…


#2

I was able to get it to run with basically your code:

var express = require ("express");
var app = express();

app.get("/", function(req, res) {
  res.send('Hello Express');
});

app.listen(3000, function() {
  console.log('Listening on port 3000');
});

And that was on port 3000. I would reboot and try again.


#3

Actually you don’t need to write the app.listen part, for the reason mentioned at line 54, myApp.js


#4

here is where I got the js script:
https://expressjs.com/en/guide/routing.html

“Hello Express” should appear on the web page.


#5

well this post is very old but on testing alot odd apostrophes throwed an error
plus require(‘express’)
not require (space) (‘express’)