RAHUL
RAHUL

Reputation: 11

How can I get html file from another folder with express?

currently I am using html file inside same folder.So how can I get a html file saved in different folder using express. Thank you.

    const express=require('express')
const path=require('path')
const app=express()

app.get('/',function(req,res){
res.sendFile(path.join(__dirname,'index.html'))
})

app.get('/about',function(req,res){
    res.send('about')
})

app.listen(3000,function(){
    console.log('Server Online')
    
})

Upvotes: 1

Views: 1076

Answers (1)

Alberto Zanovello
Alberto Zanovello

Reputation: 59

for a given url return the path of your file

app.get('/yourUrl',function(req,res){
res.sendFile("path/to/your/file.html"))
})

in your specific case try about.html instead of about?

Upvotes: 1

Related Questions