Answer the question
In order to leave comments, you need to log in
How to load a certain script depending on the address?
I am writing a small application in express and node. There was a problem. I need to load a page and a script from the html address.
I tried to connect the script to the html page, it did not work. Therefore, I wanted to ask if it is possible to load the script on the page with some function.
The code:
const express = require("express");
const app = express();
const port = 3000;
app.use(express.static(__dirname + "/public"));
app.get("/", (req, res) => {
res.render("index");
});
app.listen(port, () => {
console.log(`Server is listening on port ${port}!`);
});
Answer the question
In order to leave comments, you need to log in
Well, in the page code and write<script src="/js/script.js"></script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question