express的sendfile与send方法

sendfile:发送文件,如果将一个html的网页移到node工程,可以用此方法。

首先将html页面放到public下(统一习惯,其实放到什么地方都可以实现)。

例如想在帮订餐页面点击帮订餐跳转到订餐页面

帮订餐:

<a class="btn" type="button" href="order-meal.html">
                帮订餐
            </a>

 为引用的css指定位置即可关联

 路由:

module.exports = function (app) {
    app.get('/order-meal.html', function (req, res) {
        res.sendfile('public/pages/order-meal.html');
    });
};

 这样就实现了引用页面的跳转,

主页可以这样写:

module.exports = function (app) {

    app.get('/', function (req, res) {
        res.sendfile('public/pages/main_page.html');
    });
};

send就是向页面发送文本

module.exports = function (app) {
    app.get('/', function (req, res) {
        res.send("hello world!")
});
}

 效果如图:

猜你喜欢

转载自873719187.iteye.com/blog/2273811