How to check if the EJS is rspondendo

Asked

Viewed 223 times

2

My app is Ode with express and ejs

1 - It is running index.html and not index.ejs 2 I am unable to pass the title or title parameter to the view neither in ejs nor in html

app.js and index.ejs are like this:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var index = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', index);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;

At index.ejs it’s like this

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="!utf-8">
    <meta name ="viewport" content="width-device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie-edge">
    <link rel="stylesheet" href="stylesheets/boxstyle.css"
    <title> Index.ejs node.js web server </title>
    </head>
    <body>
    <!-- <body background="./images/fundo004.png"> -->
    <br>
    <h1> EJS no Servidor Node.js </h1>
    <h2> <%= $title %></h2>
    <br>
    <p>&nbsp;&nbsp;Bem vindo ao portal FullTime Tecnology!<p>
  <br>
  <br>
  <br>
  <br>
  <br>

    <br>
        Desenvolvimento de Sistemas.
    <br>
        Projeto de Infraestrutura em redes de dados.
    <br>
        Especificação de Equipamentos Técnicos.
    <br>
        Pesquisa Científica em Soluções de Comunicação em Tempo Real.
    <br>

  <p><a href="https://www.facebook.com/Felipe1964">Novo site! Visite FullTime.com!</a></p>

  </body>
</html>
  • How is the Javascript of ./routes/index? You can put that file here?

  • Yes, var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', Function(req, res, next) { var t = 'Express Title Parameter passed! ' res.render('index', { title: t }); }); module.Exports = router;

  • There are two files for you! There is index.js and users.js. Sorry, but I’m new to this whole architecture!

  • This one I posted you is index.js, which I believe is what you wished for.

  • and this is users.js

  • var express = require('express'); var router = express. Router(); /* GET users Listing. */ router.get('/', Function(req, res, next) { res.send('Respond with a Resource'); }); module.Exports = router;

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.