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

303
Vistas
How to correctly call a function from Node.JS to Express.JS

I have a completed script that acts as a parser. The script is written in NodeJS and it works properly. The script returns an array of data and also saves it to my computer. I would like to run this script from the frontend, at the click of a button. As far as I understand, I have to send a request to the server? It's suggested to use Express for the server, but I still haven't figured out how to call a third-party script from it, much less return any data from it. Right now all I want is for my script to run when I make a request for the root directory "/" and send me a json in response (or for example a json file)

    const express = require('express')
    const runParser = require("./parser");
    const app = express()
    const port = 3000
    

    
    app.get('/', async (req, res,next) => {
      await runParser()
        next()
    })
    
    app.listen(port, () => {
        console.log(`Example app listening on port ${port}`)
    })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

All you need for Express is this:

const express = require('express');
const app = express();
const runParser = require("./parser");
const port = 3000;

app.get("/", (req, res) => {
   runParser().then(results => {
      res.json(results);
   }).catch(err => {
      console.log(err);
      res.status(500).send("error");
   });
});

app.listen(port, () => {
    console.log(`Server running on port ${port}`);
});

And, then you can access that either by just going to:

http://localhost:3000

from your local host or

http://yourdomain.com:3000

in the browser or by issuing an ajax call to the desired URL from webpage Javascript.


I wouldn't personally put this type of activity on a GET request to / because that can be hit by things like web crawlers, search engines, etc...

It probably belongs on a POST (so crawlers won't issue it) and I'd personally put it on some pathname such as:

app.post("/runparser", (req, res) => {
    // put your code here
});

And, then use a form submission or ajax call to that URL to trigger it.

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