Basic Node And Express Serve Static Assets Not Passing Test

Tell us what’s happening:
The test isn’t passing even though the styles are being applied. Any thoughts?

I have the following code:

var express = require('express');
var app = express();
// Normal usage
app.use(express.static(__dirname + "/public"));

// Assets at the /assets route
app.use("/assets", express.static(__dirname + "/public"));

app.get("/", (req, res) => {
  res.sendFile(__dirname + '/views/index.html')
})
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1">
		<title>Hello HTML</title>
		<link rel="stylesheet" href="/style.css">
	</head>
	<body>
		<h1>Hello, HTML.</h1>
		<p>Do not use until Challenge #12</p>
     <form action="/name" method="post">
      <label>First Name :</label>
      <input type="text" name="first" value="John"><br>
      <label>Last Name :</label>
      <input type="text" name="last" value="Doe"><br><br>
      <input type="submit" value="Submit">
    </form> 
	</body>

</html>

Your project link(s)

solution: https://boilerplate-express.danielfloyd.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36.

Challenge: Serve Static Assets

Link to the challenge:

// Assets at the /assets route
app.use("/assets", express.static(__dirname + "/public"));

Why are you listening for the /assets route?

The hint section said to do that from my understanding.

1 Like

Ah, good to know. The hint section is out of date. Try attaching your app.use to the /public path instead.

EDIT: I’ve updated the guide post.

2 Likes

Awesome! That would explain why I ran into this error. Thanks you for the help and updating the hint page.

1 Like

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