8

I'm trying to make a simple hello world kind of server using Express. Here goes my code:

const express = require("express"); const app = express(); app.get("/",function(request, response){//what to do when someone make get request to the homepage or route console.log(request); response.send("hello"); }); app.listen(3000, function(){ console.log("server is listening at port 3000"); }); 

When I run the program I see this at the command prompt:

server is listening at port 3000

But when I'm accessing it through a browser i.e. https://localhost:3000, I'm getting an error:

This site can’t provide a secure connection localhost sent an invalid response. Try running Windows Network Diagnostics. ERR_SSL_PROTOCOL_ERROR

I expect the browser to see hello as per my method, above, response.send("hello")

2
  • 1
    ERR_SSL_PROTOCOL_ERROR means SSL gives you a green lock at the top left side of address bar, you can't do that with localhost, it's the s in http(s) Commented Nov 1, 2019 at 11:17
  • 3
    although you can still generate SSL for localhost , but you don't need it, just request http://localhost:3000 Commented Nov 1, 2019 at 11:17

2 Answers 2

29

You need to access it through the HTTP protocol instead. try to connect to http://localhost:3000 instead of https://localhost:3000.

Sign up to request clarification or add additional context in comments.

1 Comment

If changing to http does not work for you: in chrome, go to url: chrome://net-internals/#hsts Under Delete domain security policies enter localhost or your problem domain and click the delete button on screen Then retry with changing https to http.
6

Basically what app.listen does is that it creates an http server and listens on it, so you have to use http protocol to access it and not https.

This is the source code for app listen taken from express: app.listen

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.