Loading basic HTML in Node.js

后端 未结 20 1384
暗喜
暗喜 2020-11-28 17:34

I\'m trying to find out how to load and render a basic HTML file so I don\'t have to write code like:

response.write(\'...

blahblahblah

...\
20条回答
  •  伪装坚强ぢ
    2020-11-28 18:01

    use app.get to get the html file. its simple!!

    const express = require('express');
    const app = new express();
    
    app.get('/', function(request, response){
        response.sendFile('absolutePathToYour/htmlPage.html');
    });
    

    its as simple as that. For this use express module. Install express: npm install express -g

提交回复
热议问题