Serving up static files

I am trying to serve up the static files but nothing seems to be working. I even followed the examples that were shown through the hints.

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

console.log('hello world');

const absolutePath = __dirname + '/views/index.html';


app.use(express.static(__dirname + '/public/style.css'));

app.get('/', function(req, res){
  res.sendFile(absolutePath);
 
});

I’m doing the coding challenge from this one https://www.freecodecamp.org/learn/back-end-development-and-apis/basic-node-and-express/serve-static-assets. I would appreciate the help, thank you.

According to docs:

app.use(express.static('public'))

and it should work.

That didn’t work. I tried it on Replit and on vs code. What worked was app.use('/public', express.static('/public'));

I just tried and it works. Be sure not to have a /.

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