节点:来自服务器端的response.sendFile

时间:2018-03-29 07:44:24

标签: node.js express

嘿,我对Node.js很新。我想将公共文件夹中的index.html文件发送到客户端。我怎样才能做到这一点。

我的代码如下。此代码位于路径文件夹中的userroutes.js

router.get('/dashboard',(req,response)=>{
 if(req){

 /*if user wants to jump on dashboard without 
   login then check for request's session
 */
 /* if session exists then redirect to dashboard*/
 if(req.session.userid!=undefined){
   response.sendFile(path.join(__dirname+'/dashboard.html'));
 }

 /*if session does not exists then redirect to index.html*/
 else{
   response.sendFile(path.join(__dirname+'/public/index.html'))
 }
}
});

我的目录结构是:

click this link too see my directories

现在,当我尝试使用此代码时,它会抛出错误

  

找不到“index.html”模块

如何从服务器端将index.html文件发送到客户端?

0 个答案:

没有答案
相关问题