Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda