Node. js blog instance (10) pv statistics and message statistics, node. jspv

Source: Internet
Author: User
Tags findone

Node. js blog instance (10) pv statistics and message statistics, node. jspv

Original tutorial.

In post. js, modify var post = {...} To (after each change, clear e:/mongodb/blog ):

// Document var post = {name: this. name, time: time, title: this. title, post: this. post, tags: this. tags, comments: [], pv: 0 };
The pv key is added to the document to be stored and the initial value is 0.
Change post. getOne () in Post. js:

// Obtain an article Post. getOne = function (name, day, title, callback) {// open the database mongodb. open (function (err, db) {if (err) {return callback (err);} // read the posts set db. collection ('posts', function (err, collection) {if (err) {mongodb. close (); return callback (err);} // query collection by user name, posting date, and article name. findOne ({"name": name, "time. day ": day," title ": title}, function (err, doc) {if (err) {mongodb. close (); return callback (err);} // parse markdown to htmlif (doc) {collection. update ({"name": name, "time. day ": day," title ": title },{$ inc: {" pv ": 1 }}, function (err) {mongodb. close (); if (err) return callback (err) ;}); doc. post = markdown. toHTML (doc. post); doc. comments. forEach (function (comment) {comment. content = markdown. toHTML (comment. content) ;}) ;}callback (null, doc); // return a query Article });});});};
Note: collection. findOne ({
"Name": name,
"Time. day": day,
"Title": title
}, Function (err, doc ){

If (err ){
Mongodb. close ();
Return callback (err );
}
Here, mongodb. close (); must be placed in if; otherwise, an error is returned:

Throw new Error ('can \'t set headers after they are sent .');
Error: Can't set headers after they are sent.

The reason is that NODEJS is asynchronous. Another mongodb. close () will be executed below, and errors will occur when two asynchronous statements are executed simultaneously ;.

Modify index. ejs, user. ejs, and article. ejs, and add a line of code in the following line: <p> <%-post. post %> </p>:

<P class = "info"> Read: <% = post. pv %> | comment: <% = post. comments. length %> </p>
At this point, the article displays the number of reads and comments:




[How can I set the message board function provided by cnzz statistics as a webmaster to only allow users to view it ?]

Go to cnzz-under the statistical report, there is an advanced function-site settings-set to view the password, so you can steal it yourself.

Wordpress statistics plugin, which can be used to count the total access volume, page access volume, and downloads. It is best to count the number of online users,

The total access volume and page access volume cannot be used up with a statistical code, such as Baidu statistics.

Downloads. I recommend a DownloadManager.

The number of online users should not use plug-ins. You can integrate functions into the topic by adding a piece of php code and a call code.
I will not fill in the code, Baidu, many

To install the plugin, the following are 20 wordpress statistics plug-ins. you can install the plugin as needed.

First, Social Traffic Monitor-monitors access from multiple Social websites.
Second, the Stats-browser data statistics plug-in.
Third, Statraq-a powerful blog statistics plug-in that records visitors' IP addresses, search keywords, and number of visitors.
Fourth, Ultimate Google Analytics-more convenient addition of Google Analytics statistics scripts.
Fifth, WordPress.com Stats-WordPress official statistics plug-in requires the Wordpress API Key. (Pay now)
Sixth, WP OnlineCounter-online user statistics.
Seventh, WordPress Reporter-easily viewing Google Analytics and Feedburner statistics in the background.
Eighth, WP-SlimStat-provides all the standard statistics without generating excessive loads on the server.
Ninth, WP-Stats-a very comprehensive statistics plug-in. (Use more)
Tenth, WP-User Online-displays the number of Online users.
11th, Backlinks inbound links counter-trace the source link of the blog.
12th, Bsuite-tracking page browsing, search keywords and other content, display the most visited logs and related logs.
13th, DownloadCounter-count the number of attachment downloads.
14th, FirStats-a full-featured statistics plug-in based on AJAX technology.
15th, GeneralStats-displays the number of users, categories, articles, messages, pages, links, and so on.
16th, GoStats web counter-Easy installation of GoStats statistics code.
17th, Live-monitors blog access in real time.
18th. Open Web Analytics-collects various data and displays visitors through Google Earth.
19th, Posts/Comments Time-count the Time periods during which the most Comments are published in a day, so that you can plan the log posting Time in a more targeted manner to get more Comments.
20th, Search Phrases-count keywords from Search engines.

There is no plug-in integrated with the features you mentioned.

My blog, maid

Related Article

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.