Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda