Tag Archives: express

[Solved] Node Create Express Project Error: Failed to lookup view “error“ in views directory

Node create new Express project prompt an error: Failed to lookup view "error" in views directory

1. Use the EJS engine mode to report an error prompt FaiLED to lookup View “ERROR” in Views Directory

2. Solution
Add error.ejs to Views

<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>

3. ejstemplate engine needs to be supplemented

Node.js Error: Error: Cannot find module ‘express‘ [How to Solve]

Error:

D:\work\nodejs\1helloword>node helloword3.js
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module ‘express’
Require stack:
– D:\work\nodejs\1helloword\helloword3.js
[90m    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)[39m
[90m    at Function.Module._load (node:internal/modules/cjs/loader:778:27)[39m
[90m    at Module.require (node:internal/modules/cjs/loader:1005:19)[39m
[90m    at require (node:internal/modules/cjs/helpers:102:18)[39m
at Object.<anonymous> (D:\work\nodejs\1helloword\helloword3.js:2:15)
[90m    at Module._compile (node:internal/modules/cjs/loader:1101:14)[39m
[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)[39m
[90m    at Module.load (node:internal/modules/cjs/loader:981:32)[39m
[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)[39m
[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)[39m {
code: [32m’MODULE_NOT_FOUND'[39m,
requireStack: [ [32m’D:\\work\\nodejs\\1helloword\\helloword3.js'[39m ]
}

Solution:

D:\work\nodejs\1helloword>npm install express

added 50 packages in 2s

Error: Cannot find module ‘express’

Problem description:
System: Windows 7 x64
Node.js version: Version is: V4.2.4 LTS
Introduction to Node.js: Notes on setting up the Node.js Web development environment under Windows 7
Sample code downloaded from IBM Bluemix. Error starting debugging locally: Error: Cannot find Module ‘Express’
The diagram below:

Solutions:
Just execute the command “NPM install” in the corresponding application directory, as shown in the figure below:

Before the above operation, the command “NPM install -g Express” was also executed, I wonder if it has any effect, as shown in the figure below:

= = = = = = = = = = = = = = = = = = = = = = = = = = = = I am separated line = = = = = = = = = = = = = = = = = = = = =
Please use a word to show that although you spend Valentine’s Day alone, but not lonely……
A: Where is my pump?
B: Watching ghost movies at night, I instantly feel someone in the kitchen, the toilet, the wardrobe, and under the bed. I don’t feel bored at all…
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Valentine’s Day is the day when the mistress and the principal room rob a man, the day when the underground party rises to the surface, the day when the rose appreciates, and the day when the living are created! At 4 p.m., the florist smiled; At six o ‘clock in the evening, the owner of the restaurant smiled; At 9 p.m., the nightclub manager smiled; Midnight, the hotel owner smiled; The next day, the drugstore owner smiled; A month later, the gynecological hospital doctors and nurses all smiled.

Node.JS “Cannot enqueue Handshake after invoking quit” Error (Fixed)

module.exports = {
    getDataFromUserGps: function(callback)
    {
        connection.connect();
        connection.query("SELECT * FROM usergps", 
            function(err, results, fields) {
                if (err) return callback(err, null);
                return callback(null, results);
            }
        ); 
        connection.end();
    },
    loginUser: function(login, pass, callback)
    {
        connection.connect();
        connection.query(
            "SELECT id FROM users WHERE login = ?AND pass = ?",
            [login, pass],
            function(err, results, fields) 
            {
                if (err) return callback(err, null);
                return callback(null, results);
            }
        ); 
        connection.end();
    },
    getUserDetails: function(userid, callback)
    {
        connection.connect();
        connection.query(
            "SELECT * FROM userProfilDetails LEFT JOIN tags ON userProfilDetails.userId = tags.userId WHERE userProfilDetails.userid = ?",
            [userid],
            function(err, results, fields)
            {
                if (err) return callback(err, null);
                return callback(null, results);
            }
        );
        connection.end();
    },
    addTags: function(userId, tags)
    {
        connection.connect();
        connection.query(
            "INSERT INTO tag (userId, tag) VALUES (?, ?)",
            [userId, tags],
            function(err, results, fields)
            {
                if (err) throw err;
            }
        )
        connection.end();
    }
}

Everything worked fine at first, but when I executed the second “query, “I got this error:

Cannot enqueue Handshake after invoking quit

I’ve tried turning off the connection without using the.end() method, but it doesn’t work.
Thanked first.
Radex
Those blind solutions and water paste I will not translate.
According to:
Fixing Node Mysql “Error: Cannot enqueue Handshake after invoking quit.”:
http://codetheory.in/fixing-node-mysql-error-cannot-enqueue-handshake-after-invoking-quit/

TL; Every time DR closes a connection you need to create a new connection using the createConnection method.
And
Note: If you are serving web requests, you should not turn off the connection each time the request is processed. When the server starts up, create a connection and keep querying it with the Connection/Client object. To handle server disconnection and reconnection events you can listen for error events. Complete code: Here.
Again according to:
The Readme. Md – Server disconnects:
https://github.com/felixge/node-mysql#server-disconnects
It said

Server disconnects
You may lose your connection to MySQL server due to a network problem, server timeout, or server hanging. All of these are considered “fatal errors “and there will be an error code err. Code = 'PROTOCOL_CONNECTION_LOST'. See the error handling section for more information.
The best way to handle these unwanted disconnections is as follows:

function handleDisconnect(connection) {
  connection.on('error', function(err) {
    if (!err.fatal) {
      return;
    }

    if (err.code !== 'PROTOCOL_CONNECTION_LOST') {
      throw err;
    }

    console.log('Re-connecting lost connection: ' + err.stack);

    connection = mysql.createConnection(connection.config);
    handleDisconnect(connection);
    connection.connect();
  });
}

handleDisconnect(connection);

As the example above shows, reconnection is achieved by creating a new connection, because the connection object is designed so that it cannot be reconnected once it dies.
When a connection pool is used, suspended connections are removed from the pool and space is freed, and a new connection is automatically created when a new connection request arrives.
the respondent has posted his own autoreconnect code at the end, so I’m not going to post it here.

The answer was 18:58 on May 3, 2013
XP1
Although this answer was not adopted by the main topic, but I and the following comments have always thought that this answer is better.
The original web site: http://stackoverflow.com/questions/14087924/cannot-enqueue-handshake-after-invoking-quit