本篇文章主要介绍了"express的sendfile与send方法",主要涉及到方面的内容,对于web前端感兴趣的同学可以参考一下:
sendfile:发送文件,如果将一个html的网页移到node工程,可以用此方法。首先将html页面放到public下(统一习惯,其实放到什么地方都可以实现)...
sendfile:发送文件,如果将一个html的网页移到node工程,可以用此方法。
首先将html页面放到public下(统一习惯,其实放到什么地方都可以实现)。
例如想在帮订餐页面点击帮订餐跳转到订餐页面
帮订餐:
<a 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!")
});
}
效果如图:

以上就介绍了express的sendfile与send方法,包括了方面的内容,希望对web前端有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_303262.html