M
M
Maks Burkov2017-05-19 11:39:32
Node.js
Maks Burkov, 2017-05-19 11:39:32

How to connect to Node web server?

var express = require('express');
var app = express();
app.use(express.static('public'));
app.listen('3000',function () {
    console.log("Express server is up on port 3000!");
});

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ReactApp</title>
</head>
<body>
<h4>Hello world!</h4>
</body>
</html>

When I try to connect web-server on port 3000 I get 404! What am I doing wrong ?
The browser displays
Cannot GET /

GET localhost:3000 404 (Not Found)

5ab0157e00bf4f19a64e19b0f6120e95.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yustas Alexu, 2017-05-19
@Yuxus

404 is an error code from the server side. It means that you have successfully connected to it, but the server cannot find what you are looking for.

R
rustler2000, 2017-05-19
@rustler2000

Is the file ```public/index.html``` available?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question