Serve Static Assets. apis and microservices basic node and express

Help!

I dont know what to do, ive researched and tried different code but i just cannot pass this. The code i have

var express = require('express');
var app = express();
let absolutePath = __dirname + "/views/index.html";



app.use(express.static(__dirname + "/public"))
//app.get("/", (req, res) => {
//  res.send("Hello")
//})
app.get("/", (req, res) => {
  res.sendFile(absolutePath)
})

app.get("/json", (req, res) => {
  res.json({"message": "Hello json"})
}) 


console.log("Hello World")

What am i doing wrong?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: Serve Static Assets

Link to the challenge:

Try adding the correct path argument.

A middleware needs to be mounted using the method app.use(path, middlewareFunction). The first path argument is optional. If you don’t pass it, the middleware will be executed for all requests.

Your app should serve asset files from the /public directory to the /public path


Sorted it. Thanks so much!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.