Pretty much new to Nodejs and I’m learning it using one of the courses on pluralsight. I have written below code as part of the course, but i’m stuck with an error and can’t continue the course.
Error :
> TypeError: C:Usersthota01OneDrive - Cancer Research
> UKDesktopThotaLearningWebSite_NodejssrcviewsSessions.ejs:125
> 123| <div class="container">
>
> 124|
>
> >> 125| <% sessions.map((session, index)=>{%>
>
> 126| <div class="col-xs-12 col-sm-4 col-md-4 adj_text">
>
> 127|
>
> 128| <h3><%=session.title%></h3>
>
>
> sessions.map is not a function
> at eval (eval at compile (C:Usersthota01OneDrive - Cancer Research
> UKDesktopThotaLearningWebSite_Nodejsnode_modulesejslibejs.js:662:12),
> <anonymous>:12:17)
> at Sessions (C:Usersthota01OneDrive - Cancer Research UKDesktopThotaLearningWebSite_Nodejsnode_modulesejslibejs.js:692:17)
> at tryHandleCache (C:Usersthota01OneDrive - Cancer Research UKDesktopThotaLearningWebSite_Nodejsnode_modulesejslibejs.js:272:36)
> at View.exports.renderFile [as engine] (C:Usersthota01OneDrive - Cancer Research UKDesktopThotaLearningWebSite_Nodejsnode_modulesejslibejs.js:489:10)
> at View.render (C:Usersthota01OneDrive - Cancer Research UKDesktopThotaLearningWebSite_Nodejsnode_modulesexpresslibview.js:135:8)
> at tryRender (C:Usersthota01OneDrive - Cancer Research UKDesktopThotaLearningWebSite_Nodejsnode_modulesexpresslibapplication.js:640:10)
> at Function.render (C:Usersthota01OneDrive - Cancer Research UKDesktopThotaLearningWebSite_Nodejsnode_modulesexpresslibapplication.js:592:3)
> at ServerResponse.render (C:Usersthota01OneDrive - Cancer Research
> UKDesktopThotaLearningWebSite_Nodejsnode_modulesexpresslibresponse.js:1012:7)
> at file:///C:/Users/thota01/OneDrive%20-%20Cancer%20Research%20UK/Desktop/Thota/Learning/WebSite_Nodejs/app.js:32:13
> at Layer.handle [as handle_request] (C:Usersthota01OneDrive - Cancer Research
> UKDesktopThotaLearningWebSite_Nodejsnode_modulesexpresslibrouterlayer.js:95:5)
Code
app.js
import express from 'express';
import path from 'path';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const sessions = require('./src/data/sessions.json');
const PORT = process.env.PORT || 3000;
const app = express();
const sessionsRouter = express.Router();
app.use(express.static('public'));
app.set('views','./src/views');
app.set('view engine','ejs');
sessionsRouter.route('/')
.get((req,res)=>{
res.render('Sessions',{sessions,
});
});
sessionsRouter.route('/:id')
.get((req,res)=>{
const id = req.params.id;
res.render('Sessions',{
sessions:sessions[id],
});
});
app.use('/Sessions', sessionsRouter);
app.get('/',(req,res)=>{
res.render('index',{title:'Globomantics',data:['a','b','c']});
});
app.listen(PORT,()=> {
console.log(`listening on port number ${chalk.green(PORT)}`);
});
Sessions.ejs
<!DOCTYPE html>
<html>
<head>
<title>Globomantics</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<link href="css/style-home.css" rel="stylesheet">
<link rel="shortcut icon" type="image/x-icon" href="images/G.png" />
</head>
<body>
<div id="wrapper">
<header>
<div class="container">
<div class="logo col-md-5 col-sm-5 col-xs-8">
<a href="index.html"><img src="images/Globo-Logo-white.svg" alt="logo" /></a><span class="text">MANIACALLY
TAKING TECH TO THE GLOBE</span>
</div>
<div class="mobile-togle col-md-12 col-sm-12 col-xs-12">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" id="hamburger" class="navbar-toggle x collapsed" data-toggle="collapse"
data-target="#navbar-collapse-x">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#top"></a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-x">
<ul class="nav navbar-nav navbar-right">
<li>
<div class="search1">
<button type="submit"><i class="fa fa-search"></i></button> <input type="text" class="form-control"
placeholder="Search">
</div>
</li>
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="our-story.html">Our story<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="sessions">Sessions</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="robotics.html">Robotics</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="media.html">Media</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Support</a>
</li>
</ul>
</ul>
</div><!-- .navbar-collapse -->
</nav>
</div>
<div class="right_section col-md-5 col-xs-12">
<div class="search">
<button type="submit"><i class="fa fa-search"></i></button> <input type="text" class="form-control"
placeholder="Search">
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="our-story.html">Our story<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="sessions">Sessions</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="robotics.html">Robotics</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="media.html">Media</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Support</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="sign-in col-md-2">
<span class="dvider"></span>
<div class="sign">
<a hrf="#"><img class="sign-in-img" src="images/avatar.svg" alt="sign-in">
Sign-in</a>
</div>
</div>
</div>
</header>
<section class="sec_include">
<div class="container">
<% sessions.map((session, index)=>{%>
<div class="col-xs-12 col-sm-4 col-md-4 adj_text">
<h3><%=session.title%></h3>
<p><%=session.description.slice(0,300)%></p>
<a href="/sessions/<%=index%>" class="btn-oval">Learn More</a>
</div>
<% }) %>
</div>
</section>
<footer>
<div class="container">
<div class="main-footer col-md-12 col-xs-12">
<div class="foter-logo col-md-3 col-sm-3 col-xs-2">
<a href="index.html"><img class="desktop" src="images/Globo-Logo-white-footer.svg"><img class="mobileImg"
src="images/G.png">
</a>
</div>
<div class="links col-md-5 col-md-5 col-xs-10">
<ul class="quick-links col-md-4 col-xs-6">
<li><a href="our-story.html">Our Story</a></li>
<li><a href="#">Brands</a></li>
<li><a href="robotics.html">Robotics</a></li>
<li><a href="media.html">Media</a></li>
<li><a href="#">Support</a></li>
</ul>
<ul class="quick-links second-row col-md-4 col-xs-6">
<li><a href="#">Careers</a></li>
<li><a href="#">Privacy Policy</a></li>
<li><a href="#">Media Inquiries</a></li>
<li><a href="#">Help</a></li>
</ul>
</div>
</div>
</div>
<!---container-->
<div class="video-sec col-md-4 col-sm-12 col-xs-12">
<h1 class="video-heading text-center"><img src="images/pluralsight-white.png"></h1>
<span class="border"></span>
<p class="footer-p">This site is created for demonstrative purposes only and does not offer any real products or
services.
<p>
</div>
</footer>
</div>
<!---------- End of Wrapper ----------->
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
jQuery(document).ready(function () {
// alert("wow");
// jQuery("header").addClass("fixed");
jQuery("#hamburger").click(function () {
//alert("The paragraph was clicked.");
jQuery("header").toggleClass("fixed");
});
});
</script>
</body>
</html>