Serve static assets node js + express

link to challenge:

whats wrong with my code here :

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


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



app.use(express.static("/public", __dirname + "/style.css")

What is the purpose of the second argument in your express.static() function?

The API Docs of Express say this is an option argument.

Would be cool to see your live project so that we can test stuff.

changed it but still doesnt work, i pasted the url can you access that

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


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



app.use(express.static("/public")



https://replit.com/@egglearn/boilerplate-express-1#myApp.js

According to the instructions, you should be using the following syntax:

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


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



app.use(express.static(__dirname + "/public"))

still not working for me ?

Sorry about my earlier suggestion. It seems the challenge has changed recently. Your code above is almost there. You will need to specify a first argument that has the relative path to the “public” files (i.e. style.css) as they would appear on the site. If you notice in the boilerplate file /views/index.html, the file styles.css is referenced as:

<link rel="stylesheet" href="/public/style.css">

So, if you want the above file to show in browser with the above relative path, see if you can guess what relative path (generic and not file specific) you should add as the first argument to the following:

app.use(RELATIVE_TO_ROOT_PATH_GOES_HERE, express.static(__dirname + "/public"))
1 Like
var express = require('express');
var app = express();
absolutePath = __dirname + "views/index.html"


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



app.use("/public", express.static(__dirname + "/public"))

```

think this is right but doesnt work

That should do it. Do you see any errors in the server logs? When I fork your project and run it, the tests pass for the challenge you are on. Might need to refresh the page of the project and try running it again. Could just be repl.it having a problem.

did a few refreshes and its working, cheers Randell