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

263
Vistas
How to get this data sent to from index.js to script.js using express (Node JS)?

Beginner here...so bear with me :)

I'm getting this dataset in the console, but I can't wrap my head around getting it sent to the client side...

const { response } = require('express');
const express = require('express');
const app = express();
const port = 3000;

app.use(express.static('public'));

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));

const translate = require('sdapi').default.translate;
translate('hablar').then(console.log);

This is the result I get:

[
  {
    word: 'hablar',
    lang: 'es',
    gender: undefined,
    context: 'to articulate words',
    meaning: 'to speak',
    part: 'intransitive verb',
    examples: [ [Object] ],
    regions: []
  }]

I've tried wraping it into a app.get('/translation', async (req, res) => {}) but it doesn't work.

Appreciate your time/attention.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

app.get('/translate/:word', async (req, res) => {
  const {
    params: { word },
  } = req; // same as const word = req.params.word
  const translatedWord = await translate(word); // same as .then

  return res.status(200).json({ translatedResponse: translatedWord });
});

To activate this you have to send http get request to whateverip:port/translate/<WORD_TO_TRANSLATE_INPUT>

You can send http requests with axios, curl, or fetch and your browser's terminal thouhg the last one isn't always optimal solution.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think you want to check your controller and sed data to it so the first step that u must do to install body-parser with npm i body-parser

then use it like

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

now u can receive and store your data on request.

then learn about the request (https://expressjs.com/en/guide/routing.html)

then u can send a request to your server with postman or Axios or curl and something else .

I hope to solve your question.

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