This is my first time working with node.js and Express. I have the following project structure:
Project/
|-- app/
| |-- script.js
|
|-- public/
| |-- css/
| |-- style.css
| |
| |-- resources/
|
|-- views/
| |-- index.ejs
|
|-- app.js
|-- package.json
|-- package-lock.json
Now:
- app.js -> starts the server
- index.ejs -> contains the html code
- style.css -> has the styling
- script.js -> contains the front end functionality of my application
Before creating the server so that my application is run from there, the script file was simply included in the index.html (now the index.ejs) as usual, and everything worked fine. But now just including the script file in the ejs is not enough. In fact, the page just loads on the server but nothing functions.
I have tried adding the following in my script.js file as I found something on here, but it didn't work:
const express = require("express");
path = require('path');
const script = express();
script.use(express.static(path.join('../views', 'index')));
What do I have to do to link my script.js file with node.js and express, without having to develop a RESTful application?