Node.js error i don't know this error help me

node.js error i don’t know this error help me

TypeError Cannot read property ‘render’ of undefinded

var fs = require('fs');
var ejs = require('ejs');
var mysql = require('mysql');
var express = require('express');
var bodyParser = require('body-parser');

var client = mysql.createConnection({
    host:'localhost',
    user:'root',
    password:'1234',
    database:'company',
    port:'3306' ,
    multipleStatements : true
});

var app = express();

app.use(bodyParser.urlencoded({extended:false}));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

app.get('/',function(req,res){
    fs.readFile('./views/book_list','utf8',function(err,ejs){
        client.query('SELECT * FROM book',function(err,results){
            if(err){
                console.log('select all queart error');
                console.log(err);
            }else{
                res.send(ejs.render({data:results}));
            }
        });
    });
});

``

            <th>EDIT</th>

            <th>bookid</th>

            <th>title</th>

            <th>author</th>

            <th>publisher</th>

            <th>pub_date</th>

        </tr>
        <%
        for(var i=0; i<data.forEach; i++)  
        {
        %>
            <tr>
                <td><a href="/delete/ <%= data.id %>">DELETE</a></td>
                <td><a href="/edit/ <%= data.id %>">EDIT</a></td>
                <td><%= data.book_id %></td>
                <td><%= data.title %></td>
                <td><%= data.publisher %></td>
                <td><%= data.pub_date %></td>
            </tr>
        <%}%>
    </table>
</form>
DELETE
1 Like

First of all I recommend you dropping var and use const or let (if the variable’s content can change).

For example: const fs = require('fs');

Regarding your error TypeError Cannot read property ‘render’ of undefinded you have to look, where this function get called:
Line 29: res.send(ejs.render({data:results}));

it seems, that the imported package ejs is undefined, not loaded properly. So check, if this file is actually defined in your package.json and installed in your project (node_modules) folder.