A
A
Artyom2020-03-01 20:25:45
Express.js
Artyom, 2020-03-01 20:25:45

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

1 answer(s)
A
Alexey Yarkov, 2020-03-01
@airman66

Well, in the page code and write<script src="/js/script.js"></script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question