Why can't I import js and css with express in node

The code I wrote for routing to the site was this.
app.get("/trolled", function (request, response) { response.sendFile(__dirname + "/trolled/index.html"); });
It won’t implement the css and js and in the browser console it shows this.


It only has the HTML put on the page and I know I imported it with html.

It’s because your server isn’t serving those files. You need to move funnyhehe.css and script.js to the public folder and inside a folder called trolled.

public
   trolled
      script.js
      funnyhehe.css
server.js
package.json
README.md
LICENSE.md
.env
.gitignore

Just did that but it still won’t add them to the page

Now move this

<script src="trolled/script.js"></script>
<link rel="stylesheet" href="trolled/funnyhehe.css" />

To this

<script src="/script.js"></script>
<link rel="stylesheet" href="/funnyhehe.css" />

in index.html

The index.html in the /trolled file or /public file?

Never mind, Just had to remove the / thank you for the help

2 Likes