NodeJS + Express served HTML file not loading js file?

后端 未结 2 647
不思量自难忘°
不思量自难忘° 2021-01-02 01:06

I am running a NodeJS server which uses a catchall route to serve a file \'index.html\'. In that file, I am linking to a javascript file in the same directory. That javasc

2条回答
  •  情书的邮戳
    2021-01-02 01:44

    You should set your static folder like this

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

    Also, your html file will look inside the /public folder itself for your script file. You'll need to give your index.html file the right path to your script file.

    
    

提交回复
热议问题