Open In App

How to Create a Pre-Filled forms in Node.js ?

Last Updated : 13 Feb, 2023
Like Article

Pre-Filled forms are those forms that are already filled with desired data. These are helpful when a user wants to update something like his profile, etc. We just create a folder and add a file, for example, index.js. To run this file you need to run the following command.

node index.js

Filename: SampleForm.ejs 


<!DOCTYPE html>
    <title>Pre-Filled Form Demo</title>
    <h1>Update User</h1>
    <form action="saveData" method="POST">
            Email    : <input type="text" name="email"
                        value='<>'> <br>
            Name     : <input type="text" name="name"
                        value='<>'> <br>
            Number   : <input type="number" name="mobile"
                        value='<>'> <br>
            Address : <input type="text" name="address"
                        value='<%=user.address%>'> <br>
            <input type="submit" value="Submit Form">

Filename: index.js 


const express = require("express")
const path = require('path')
const app = express()
var PORT = process.env.port || 3000
// View Engine Setup
app.set("views", path.join(__dirname))
app.set("view engine", "ejs")
app.get("/", function(req, res){
    // Sample data to be filled in form
    var user = {
        email: '',
        name: 'Gourav',
        mobile: 9999999999,
        address: 'ABC Colony, House 23, India'
            user: user
app.listen(PORT, function(error){
    if(error) throw error
    console.log("Server created Successfully on PORT", PORT)

Steps to run the program:

  1. The project structure will look like this: project structure
  2. Make sure you have installed ‘view engine’ like I have used “ejs” and also installed express module using following commands:
npm install express
npm install ejs
  1. Run index.js file using below command:
node index.js
  1. console output
  2. Now Open browser and type this URL:
  1. Then you will see the Pre-Filled Update User Form as shown below: output

So this is how you can create your own Pre-Filled forms.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads