Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!