2

I would like to add some backend functionality for payment option for my small Firebase web app. My project has the following structure.

project 
| functions (cloud functions here)
| --server.js
| static (all JavaScript files for frontend, css, images)
| --style.css
| --index.js
| --images
| index.html
| other HTML files
 

Here is what I have inside my server.js file. I am getting net::ERR_ABORTED 404 (Not Found) for all my JavaScript files. What should I do here?

const express = require('express');
const app = express();

app.set('view engine', 'ejs');
app.use(express.static('../../project'));

I noticed the following two possible posts that might help me, I tried some top answers from there but still stuck, do not actually understand where is the problem and what has to be done.

JS file gets a net::ERR_ABORTED 404 (Not Found)

How do I use HTML as the view engine in Express?

Soni Sol
  • 2,367
  • 3
  • 12
  • 23
user12051965
  • 97
  • 9
  • 29
  • I'd like to understand your project better. Can you please provide your front end file that uses your server.js? – MrTech Sep 14 '20 at 19:34

1 Answers1

1

The problem I noticed here is this line app.use(express.static('../../project')); What you are doing is setting the folder project to public. Your JS files are inside a static folder, and they do not get read. I would suggest the following structure:

project 
  server.js
  static (folder)
    HTML (folder for all HTML files)
    css (folder for all css files)
    js (folder for all js files)

Then in your server.js file:

const express = require('express');
const app = express();

app.set('view engine', 'ejs');
app.use(express.static('./static'));
gshow8 shac
  • 391
  • 2
  • 15