Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
Access one function on other file

I would like connect the function of file home.html to file index.js. It's possible?

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

app.use(express.json());

app.listen(
    Port,
    () => console.log('its alive on http://localhost:' + Port)
);

var url = [];
var User = [];

app.post('/tshirt/:id', (req, res) => {
    if (req.body.Request == "NovaMusica") {
    
    res.send({
        Musica: req.body.Musica, User: req.body.User
    });
        url.push(req.body.Musica);
        User.push(req.body.User);
        var testa = require('./home.html');
        testa.test(url, User)

    
    }});

home.html:

<html><head>
<script>
export function test(... args){
    $.each(url, function(index, value) {
        $('<label style="margin-top:15px;display:inline-block;margin-left: 5%;">'+url[index]+' (time)<br><br>&emsp;&emsp;&emsp;'+User[index]+'</label>', {
          'text': value
        }).appendTo('sendMusics');
      });
}

I would like connect function test of home.html to request on app.post.

It's possible? Thanks for helping me

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Note: You cannot run client-side, DOM-manipulating JS on the server; it requires a browser with your page loaded to run.

Nonetheless, here's what you'd need to do in more useful cases:

Move the script from the HTML to a file test.js:

// test.js
function test(... args){
    $.each(url, function(index, value) {
        $('<label style="margin-top:15px;display:inline-block;margin-left: 5%;">'+url[index]+' (time)<br><br>&emsp;&emsp;&emsp;'+User[index]+'</label>', {
          'text': value
        }).appendTo('sendMusics');
    });
}

export { test };

Then inside home.html replace the inline script by

<script src="./path/to/test.js" type="module"></script>

So inside your index.js you can then import it (at the top of your file):

import { test as testa } from './path/to/test.js';
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!