So my goal is, right now, to use NodeJS and express together to take the data I get from a form and write it to a local file. The local file is located on my computer i.e. the server (since I am using localhost). Now, I am able to render the form, but how do I add functionality to this form? Because whenever I create an index.js file in the views folder, the html is not able to access it until and until and unless I dont move it to a public folder, which is the static files folder, the html cant access the js file. Now, when I transfer it to the statics folder, require suddenly stops working.
server.js:
const path = require('path')
const app = express()
app.use(express.static(path.join(__dirname, 'public')));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.get("/", (req, res) => {
console.log("here")
res.render("index")
})
app.listen(3000)