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

311
Vistas
Post data on another page in nodejs

I'm new in nodejs. I'm trying to make login form using ejs engine. What I want is simply print the username and password in the welcome screen using post request. The problem is that if I am using POST action it will print my data but don't display the welcome screen layout and if I used GET action then it will display the screen layout but don't have the data. I have wrriten the code in the app.js file. Is it correct?? I've mentioned my app.js code below for reference. Thanks in advance.

Code:-

app.post('/welcome', function(req, res) {
     res.send('Username is '+req.body.unm+'<br>Password is '+req.body.pwd);
});
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

What issue are your facing? Is the return string not displaying the values? When using template engines you should use generally use render instead of res.send to send the view.

Check the sample s given in ejs home page.

over 4 years ago · Santiago Trujillo Denunciar

0

There's some really useful information on the ejs npm page: https://www.npmjs.com/package/ejs

I suggest you look into the express package, which allows you to serve pages, so you would start with something like this:

app.get('/', function(req, res){
  return res.sendFile(__dirname + '/index.html');
});

Here's a useful answer which will help you out: how to implement login auth in node.js

over 4 years ago · Santiago Trujillo Denunciar

0

If you are using express with ejs, you need to define the folder that houses your views (.ejs files) like this:

var express = require('express')
app.use(express.static(__dirname + '/views')); // set the static files location for the static html

And instead of res.send, respond with this:

app.post('/welcome', function(req, res) {
        res.render('welcome', {username: req.body.unm, password: req.body.pwd});
});

Construct your html in welcome.ejs and put place holders for <%= username %> and <%= password %>

Sample welcome.ejs file in views directory in project base:

<div class="container">
    <p>Welcome<b><%= username %></b></p>
    <p>Your password is <%= password %> </p>
</div>
over 4 years ago · Santiago Trujillo 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