Kesavan Subramanian
Kesavan Subramanian

Reputation: 21

how to connect ejs file to .js file?

app.js image

i have two files app.js and landing.ejs and while running server ,it displays no error and the server is running but when i go to http://localhost:3000/ iam getting the name of the ejs file ,not the html content in the ejs file..please help me with this.

browser image

enter image description here

Upvotes: 0

Views: 1087

Answers (1)

Ehsan ul haq
Ehsan ul haq

Reputation: 107

Use this code in your app.js file. Set ejs view engine in app.js

   var express = require('express');
   var app = express();

   // set the view engine to ejs
    app.set('view engine', 'ejs');
    app.set("views", "views/")

Then use get request for your landing page in your app.js file

    app.get('/', function(req, res) {
       res.render('views/landing');
     });

Upvotes: 1

Related Questions