Basic Node and Express - Serve an HTML File

Tell us what’s happening:

Hello,

I’m stuck here and can’t figure out why this won’t pass…

let app = express();




/*app.get("/", function(req, res) {
  res.send("Hello Express");
}); */


app.get("/", function(req,res){
  res.sendFile(absolutePath= __dirname +'views/index.html')
})



###Your project link(s)

solution: https://09f9630c-e4c2-43cb-b57b-e4cbbedfc78c-00-37buwsj8bya8l.janeway.replit.dev

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

Challenge Information:

Basic Node and Express - Serve an HTML File

your path is incomplete, take a new look at the example, or check what is the value of

also note that doing an assignment where you need the value is not a good pattern

I’m not really sure what you mean, I’m also doing this app.get("/", function(req,res){ res.sendFile('__dirname + /views/index.html') }) and I can’t figure out what i’m doing wrong…

do you see the form as told in the description?

ENOENT: no such file or directory, stat '/home/runner/workspaceviews/index.html'
However I do see the folder views and the file index.html within, I’m using replit.

in this one you are not creating the path properly, do not forget how to work with strings at this point

  res.sendFile(__dirname + "/views/index.html")
})  

I don’t know, please give me another hint…

Also,

Why is the first part of the code being omitted :

app.get(“/”, function(req,res){
res.sendFile(__dirname + “/views/index.html”)
})

does the path here appear correct?
workspaceviews does not seem the correct folder name, if the folder is views

Yes, and in my code it’s views/index.html which is also what I see in replit, I don’t know where the workspaceviews thing is or what it is…

from __dirname, did you check what’s its value?

the path is missing something

Please check the message above, I don’t know what to do…

from your message? it happens to whatever you put on the same line as the three backticks

after you have wrote this, did you restart the server? did you try again?

Hi, I have restarted the server (reloading the page will do it in replit, right?).

Now I get path must be absolute or specify root to res.sendFile , how do I fix this and move forward already?

app.get("/", function(req,res){
  res.sendFile("__dirname + /views/index.html")
})

did you do the JavaScript certification before moving to this one?

log the value of this

I did parts of it and am still working on it, I want to learn some Node also, what does that have to do with you helping me to move forward? Please help me with this current problem I’m having, I’m not asking for the answer, just tell me what I’m doing wrong and give me another hint, that would help, thanks.

you are having issues with concatenating a variable and a string, do you see here how you are not concatenating the variable __dirname with the string /views/index.html?

if this is something you have issues with I suggest more JavaScript practice first, you can do the full stack curriculum javascript section

add a console.log rigth above and test the value of that

Hi, I had already tried that several days ago with

app.get("/", function(req,res){
  res.sendFile(__dirname + "/views/index.html")
}) 

in this example above I am concatenating the variable __dirname with the string “/views/index.html”

This is the error that I get:

path must be absolute or specify root to res.sendFile 

where do you get that error?

In replit when i look at the preview while the server is running