Using the NODEJS environment and relying on the third-party library, framework and so on to realize the site separation error problem and processing method

Source: Internet
Author: User

Use NODEJS environment and rely on third-party library, framework and so on to achieve the site separation error problem and processing method problem one:

syntaxerror:missing) after argument list in ... \views\user\index.html while compiling ejs.

Syntax error: Loss of closing parenthesis) at the end of the argument list, in the \views\user\index.html (index.html in this path) when compiling Ejs.

Analysis: This time should be the template engine ejs problems, but Ejs is already a well-written template library, there is no problem, so we should go to replace the page to find the problem.

Processing method: This time we should go to inndex.html to find the problem, pay special attention to the contents of the delimiter <%%>, as long as the attention and index.html files, so reduce the scope of the error, clear thinking can be ruled out the problem.

Question two:

Trying to open unclosed connection.

Try to open a connection that is not closed.

Analysis: Through connection we can think of the Operation Mongoose.connect (' mongodb://localhost/database name ') connected to the database, so we may have used the connection database operation multiple times ( This is because in the Routers folder, each JS file is written) or after the operation is completed we did not close the database (method one: mongoose. Connection. close (), equivalent to db. ().   Method Two: mongoose. )

Processing method: We connect the database one time, not many times to the database. Create a new Libs folder under Express custom project name and create a new model.js under Libs with the following content
var mongoose = require (' Mongoose ');
Mongoose.connect (' mongodb://localhost/database name ');
Exports.mongoose = Mongoose;
JS file under the Routes folder, introduced as
var mongoose = require ('.. /libs/model.js '). Mongoose; Then define the model again.

Question three:

Can ' t set headers after they is sent.

Cannot set the head again after sending (personal understanding is the head in the request and response)

Write Express made the mistake, the original project when my idea is to respond to the page, 3 seconds to jump to the registration page, the results of an error, tried for a long time I solved the method is to remove a res method is good), the code is as follows

 1  router.get ('/jump ', function   (req, res) { 2  //
     3  res.render (' User /jump ', {success:req.flash (' success '). ToString (), Error:req.flash (' Error '  4  setTimeout (function   () { 5  //  Redirect to reg.html  6  res.redirect ('/users/reg '  7 },3000);     8 }); 

The solution is to remove one of the res methods, but not to reach the demand, due to limited capacity, there is no solution to this demand problem. There are references to this blog post, but my problem is not due to the asynchronous way of Nodejs, which is hereby documented so that this problem can be avoided later.

   

    

Using the NODEJS environment and relying on the third-party library, framework and so on to realize the site separation error problem and processing method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.