Node. js blog instance (6) message function, node. js instance
Original tutorial.
This function enables users to leave messages for articles. The messages are stored in the database.
Post. js, modify the document to be saved in Post. prototype. save as follows:
// Var post
API in Node. js. I hope it will be useful to you.
Features
Event-based communication
You can use pipe to connect to a stream.
Type
Readable Stream Readable data Stream
Writeable Stream writable data Stream
Duplex Stream bidirectional data Stream, which can be read and written simultaneously
Transform Stream converts data streams, which are readable and writable,
Here we will share with you node. examples of js operations on the mongoDB database, including connecting to the database, inserting data, closing the database, reading data, and inserting data, are very comprehensive. We recommend this to our partners.
Connect to database
The Code is as follows:
Var mongo = require ("mongodb ");Var host = "localhost ";Var por
": "testuser3", "email": "testuser3@testdomain.com"}]Db. usercollection. insert (newstuff );Note that multiple data entries are transmitted to the collection at a time through one data entry. Easy! Use the find command above to view the three data items.
Now we can integrate the web servers and databases we have built.
Step 2-connect mongo to node
Now let's create a page to display the records in the data
This article mainly introduces Node. for details about js file operations, this article describes how to process file paths and how to use and introduce the fs module in detail. For details, refer to a set of data flow APIs on Node, it is convenient to process files like network streams, but it only allows sequential processing of files and does not allow random
of the _write method, the focus is on the details of the data stream writing
Stream. Duplex read/write stream (need to implement the above two interfaces, the attention point is the details of the above two interfaces
Stream. Transform inherits from Duplex (_transform method needs to be implemented, the focus is on the processing of data blocks
In simple terms:
The owner of the pipe () must have the readable stream (not limited to) the ability to have the ' readable '/' da
This article mainly introduces Node. js uses the dependency injection-related issues and solutions, Node. js is a framework that runs JavaScript applications on the server. if you need JavaScript, refer to the recent introduction. I turn to dependency injection to help you understand the simple way to separate code and
How to learn: read it in detail and implement the relevant code manuallyLearning Goals : This tutorial will teach you to install node, build servers, Express, MySQL, MongoDB, write background business logic, write interfaces, and finally complete a complete project backstage, a total of 10 days is expected.node. js Operation MangodbCreate a folder for placing today's files, NPM init initializes, and creates
The seventh chapter recommends 4 hours of study time 10 chaptersHow to learn: read it in detail and implement the relevant code manuallyLearning Goals : This tutorial will teach you to install node, build servers, Express, MySQL, MongoDB, write background business logic, write interfaces, and finally complete a complete project backstage, a total of 10 days is expected.node. js Operation MangodbCreate a fol
Great routine analysis of node. js Reading Notes, node. js Reading Notes
This week, nodejs learned how to use several dependent packages and used all the examples in the book. This article takes the routine as a clue to review the work of the week.
1. connect
This routine ma
This article mainly introduces. A simple method for reading and writing Redis databases in js applications. Redis is a memory-based high-speed Database. if you need it, please ensure that Redis and Node are installed before you start this article. js and Node. redis extension of js
This article mainly introduces. A Simple Method for reading and writing Redis databases in js applications. Redis is a memory-based high-speed database. If you need it, please ensure that Redis and Node are installed before you start this article. js and Node. redis extension of js
This article describes how to use the Client Session in Node. js programming. It is the basic knowledge of Node. js beginners. If you need it, you can refer to the static website for easy extension. You only need to cache all the data and do not need to consider combining stateful content from different servers to user
;}.nextpage a{float:right;text-decoration:none;padding:.5em 1em;color:#ff0000;font-weight:bold;}.prepage a:hover,.nextpage a:hover{text-decoration:none;background-color:#ff0000;color:#f9f9f9;-webkit-transition:color .2s linear;}Effect:
11 articles published above =
Click Next page
The ghost code requires more activity and more water.
In the example of creating a microblog in the nodejs Development Guide, an error is reported during the process of creating a registered account.
It is setting
This article mainly introduces Node. js uses the dependency injection-related issues and solutions, Node. js is a framework that runs JavaScript applications on the server. If you need JavaScript, refer to the recent introduction. I turn to dependency injection to help you understand the simple way to separate code and
follows:
Head-10 some.txt | node parser. js
For a Readable stream, we can also subscribe to its data and end events to obtain data blocks and receive notifications when the stream is exhausted, as in the typical socket example:
The Code is as follows:
Req. on ('connect ', function (res, socket, head ){Socket. on ('data', function (chunk ){Console. log (chunk.
Node. js static file server ultimate version, node. js static ultimate version
First, I would like to thank github for providing the source code on github. Compared with last night's static file server, it is a little more complex and can learn a lot of new things.
The Code contains a fs. stat function and the pipe fun
. After all, Node develops so fast.
If you carefully read the README document, you do not need to read the subsequent steps to avoid misleading you due to version inconsistency.
4. Connect to the mysql database
Go to the project document, create a TestMysql. js example, and write the following code:
var mysql = require('mysql');var connection = mysql.createConn
This article describes how to implement routing in node. js. As the name suggests, routing means that we have different processing methods for different URLs. This article will teach you how to implement routing in node. js. to implement the routing function in js, you can r
This article mainly introduces. the Redis method is used in js applications, and the simplest data read/write operations are related. if you need it, please ensure that Redis and Node are installed before you start this article. js and Node. redis extension of js -- node_red
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.