Node.js+express cannot enter the post blog page when creating a blog.

  node.js, question

The post page appears as:Moved Temporarily. Redirecting to http://localhost:3000/
The terminal displays as (ubuntu14.04 for me):

user is not defined
 at __line (eval at <anonymous> (/home/lu/node/blog/node_modules/ejs/lib/ejs.js:464:12), <anonymous>:14:12)
 at eval (eval at <anonymous> (/home/lu/node/blog/node_modules/ejs/lib/ejs.js:464:12), <anonymous>:39:9)
 at returnedFn (/home/lu/node/blog/node_modules/ejs/lib/ejs.js:493:17)
 at View.exports.renderFile [as engine] (/home/lu/node/blog/node_modules/ejs/lib/ejs.js:350:31)
 at View.render (/home/lu/node/blog/node_modules/express/lib/view.js:76:8)
 at Function.app.render (/home/lu/node/blog/node_modules/express/lib/application.js:504:10)
 at ServerResponse.res.render (/home/lu/node/blog/node_modules/express/lib/response.js:801:7)
 at /home/lu/node/blog/routes/index.js:108:7
 at callbacks (/home/lu/node/blog/node_modules/express/lib/router/index.js:164:37)
 at param (/home/lu/node/blog/node_modules/express/lib/router/index.js:138:11)
 GET /post 500 31ms - 100b
 
 http.js:691
 throw new Error('Can\'t set headers after they are sent.');
 ^
 Error: Can't set headers after they are sent.
 at ServerResponse.OutgoingMessage.setHeader (http.js:691:11)
 at ServerResponse.res.setHeader (/home/lu/node/blog/node_modules/express/node_modules/connect/lib/patch.js:63:22)
 at /home/lu/node/blog/node_modules/express/node_modules/connect/lib/middleware/errorHandler.js:63:17
 at fs.js:266:14
 at Object.oncomplete (fs.js:107:15)

Post.js code:

var mongodb = require('./db');
 
 function Post(name, title, post) {
 this,name = name;
 this.title = title;
 this.post =post;
 bracket
 
 module.exports = Post;
 
 //Store an article and related information
 Post.prototype.save = function (callback) {
 var date = new Date();
 //Store various time formats for future expansion
 var time = {
 date: date,
 year: date.getFullYear(),
 Month: date.getFullYear () plus "-"plus (date.getMonth () plus 1),
 Getfullyear () plus "-"plus (date.getMonth () plus 1) plus "-"plus date.getDate (),
 Minute: date.getFullYear () plus "-"add (date.getMonth () plus 1) "-"add date.getDate () plus ""add date.getHours () plus ":"add (date.getMinutes() < 10?  0' plus date.getminutes (): date.getminutes ())
 bracket
 //Documents to be Stored in Database
 var post = {
 name: this.name,
 time: time,
 title: this.title,
 post: this.post
 };
 //Open the database
 mongodb.open(function (err, db) {
 if (err) {
 return callback(err);
 bracket
 //read posts collection
 db.collection( 'posts', function (err, collection) {
 if (err) {
 mongodb.close();
 return callback(err);
 bracket
 //Insert document into posts collection
 collection.insert(post, {
 safe: true
 }, function (err) {
 mongodb.close();
 if (err) {
 return callback(err);  //Failure!  Return err
 bracket
 callback(null);  //err returned is null
 });
 });
 });
 };
 
 //Read articles and related information
 Post.get = function(name, callback) {
 //Open the database
 mongodb.open(function (err, db) {
 if (err) {
 return callback(err);
 bracket
 //read posts collection
 db.collection('posts', function (err, collection) {
 if (err) {
 mongodb.close();
 return callback(err);
 bracket
 var query = {} ;
 if (name) {
 query.name = name;
 bracket
 //query articles based on Query objects
 collection.find(query).sort({
 time: -1
 }).toArray(function (err, docs) {
 mongodb.close();
 if (err) {
 return callback(err);  //Failure!  Return err
 bracket
 callback(null, docs );  //Success!  Returns the results of the query as an array
 });
 });
 });
 };

Ask for help! ! Thanks a lot.

  1. No problem found. Have you given all your err_msg?

  2. Post.js fourth linethis,name = name;insteadthis.name = name;, try;

  3. According to the error message, it seems that there is a place to set the response header after returning the request.
    That’s all.