There is an example from the textbook (Pyurival S. Basics of Web Application Development, 2015, p. 197). A virtual machine is created there and the server is started on it in JavaScript, the http and Express module is used.

var express = require("express"), http = require("http"), app = express(); app.use(express.static(__dirname + "/client")); //в папке есть файл index.html http.createServer(app).listen(3000); app.get("/hello", function (req, res) { res.send("Hello, World!"); }); app.get("/goodbye", function (req, res) { res.send("Goodbye, World!"); }); 

When using the link http: // localhost: 3000 / index.html writes: Cannot GET /index.html. In this case, the previous examples (where there is no request to the files) work, but this one is not. Tell me, please, what to do?

  • index.html you exactly lies in the subfolder client? Right now I checked your code, everything works. - Yaant

1 answer 1

The reason was the incorrect placement of the client directory. Although I did everything according to the textbook, but according to the Express manuals, I need to go to the same directory where the executable file server.js is located. __dirname just goes there. I read the tutorial more carefully: all because of a bad translation (first the creation of a folder in one place is indicated, and then the context indicates that the folder should be in another). I would like to know if I don’t specify the glob variable, then where should the client be located?