how to import variable from ejs prompt to js file

Viewed 9

I need to import variable from ejs prompt to another javascript file, how can i do that? I need to make sure that the user, after opening the website, fills in a prompt that will be like a variable and I will be able to use it in the text on the website.

webserver.js

const express = require("express");
const webserver = express();
const port = 8080;


var prompt = " THERE I NEED INPUT FROM EJS PROMPT "


webserver.set('view engine', 'ejs');

webserver.get('/', function(req, res) {
    res.render('index', {
        prompt: prompt,
    });

index.ejs

<script> var prompt = prompt("your name: "); </script>

<h1 class="main-text">Welcome <%= prompt %> !</h1>

0 Answers
Related