alittlestupid
alittlestupid

Reputation: 11

javascript file doesn't find in my express app

I got this error GET http://localhost:3000/assets/index.js net::ERR_ABORTED 404 (Not Found)

const express = require ('express')
const app = express()
const { join } = require('path')

app.use(express.static(join(__dirname,'/public')))

my folder structure:

enter image description here

the js is for survey.html:

<script src="/assets/index.js"></script>

anyone know why I got this error?

i tried

<script src="./assets/index.js"></script> 

doesn't work

Upvotes: 1

Views: 61

Answers (1)

user7976244
user7976244

Reputation:

It should be app.use(express.static(join(__dirname,'public'))). adding / to the public means it looks in the root filesystem.

EDIT:

Oh, it is actually in the comment:

app.use(express.static(join(__dirname,'public'))) Use this – Yatin Gaikwad

Upvotes: 2

Related Questions