search

Home  >  Q&A  >  body text

node.js - Don't understand res.sendFile(path.resolve('./public'))

This is my code structure

I used this code in app.js so that my index.html and movieDetail.html can be accessed, but I don’t know what this code means. Please answer

app.use('*', function (req, res) {
   res.sendFile(path.resolve('./public'));
 })
漂亮男人漂亮男人2735 days ago877

reply all(3)I'll reply

  • 为情所困

    为情所困2017-06-05 11:15:38

    This statement is equivalent to all requests coming in, searching for the requested file in the current public directory of the project, and returning it when found. Your indez.html and movieDetail.html are in the public directory, and of course they will be returned

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-05 11:15:38

    The route is parsed to the corresponding html page under public

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-05 11:15:38

    All are contents of the express framework, please refer to the official documents http://expressjs.com/en/4x/ap... and http://expressjs.com/en/4x/ap... . Simply put, the meaning of this code is to match all routes and return the specific file under the public path after receiving the request.
    You can also read the Chinese documentation: http://www.expressjs.com.cn/4... and http://www.expressjs.com.cn/4...

    reply
    0
  • Cancelreply