How to render a HTML page form NodeJs API?

前端 未结 1 1756
醉梦人生
醉梦人生 2021-01-29 02:55

**After running http-server, I try to get to URL- http://127.0.0.1:8080 - but instead of what I write, I get \"Node.js v8.11.4/ ecstatic server running @ 127.0.0.1:8080\"` eve

相关标签:
1条回答
  • 2021-01-29 03:11

    Looks to me like you are not able to find end-point which respond your HTML page. Every url is an API which make request to server. The url which we type on browser are GET API.

    Your http://localhost:8080 and http://127.0.0.1:8080 are API with end-point as /.

    If you are using expressJs then look for something like this:

    app.get('/yourAPI/', (req, res) => {
        //res.render is function that send html page to browser
        res.render('htmlFile');
    });
    // So your page will be available on http:127.0.0.1:8080/yourAPI
    // or http://localhost:8080/yourAPI
    

    Note your function should be app.get() as you wont be able to call app.post from browser.

    You need to find out end-point which response HTML page.

    0 讨论(0)
提交回复
热议问题