Talk about node. js, which has been studying for some time recently

Source: Internet
Author: User
Tags mongodb query using git

Official notes

1.NodeJS declared its goal to be "designed to provide a simple way to build scalable network programs."

2.node is a lightweight, scalable JS operating environment with event-driven and non-blocking I/O mechanisms based on the Chrome V8 engine for code interpretation.

The 3.node is suitable for projects with high concurrency requirements and is suitable for high I/O intensive applications.

so: not suitable for CPU-intensive applications;

The main challenge for CPU-intensive applications is that because of the JavaScript single thread, if there are long-running computations (such as cycle), the CPU time slices will not be released, causing subsequent I/O to fail to originate. However, the large operations can be decomposed into several small tasks, so that the operation can be released in a timely manner, without blocking the initiation of I/O calls.

4.node is very hot now.

/-----------------------------------------------------------------------/

I understand.

My understanding of node. JS is that since I started using git and webpack, because of the node environment and the ability to touch a subset of the node console code, these are simple things to know that node is a setup environment that allows git and webpack to run and is a NPM package Management tools, you need what code, node's package will also have a part, such as Jquery,bootstrap;

Then is to start to see the file node website, understand that node can be used as a background language for a series of operations, can build their own server, as a server when we will use the HTTP module, which belongs to the module of node, and then the Createserver build server, Later felt that NPM created to open the server compared to the trouble, on the internet to learn that there is a supervisor this plug-in bar, you can listen to the server, and then began to consider as a background function, than the background to the data before you test it, and then, for example, Learn about the server and the communication between the terminal Socket and H5 new WebSocket, do some chat room demo, of course, a bit ugly, but the basic dialogue function is based on sorket implementation.

Sometimes node also needs to be linked to the database, the database port is 27017---the following in the node in the route/liuyan----> Database user, set Liuyan to do a simple find demo

MySQL I have a little to understand, and for SQL Server is only limited to the knowledge of the school, then in the online learning to see another kind of MongoDB, (later on next);

var router = Express. Router (); var MongoDB = require ("MongoDB"). Mongodbclient;var db_str = "mongodb://127.0.0.1:27017/{{Your database name}" Router.get ("/liuyan", (req, res) = = {     // Res.render ("Liuyan", {});        var findly = function (db, CB) {           var conn = db.collection ("Liuyan");           Conn.find ({}). ToArray (err, result) = {               CB (result);           })        }   Mongodb.connect (Db_str, (err, db) = = {      if (!err) {          findly (db, (result) = = {              Res.render ("Liuyan", {R Esult:result});              Db.close (),})})   

In a nutshell, MongoDB, I use this database also because of node. js, and the console code I do not remember very clearly, so often in the small rocket V3 visualization tools to manipulate MONGODB data.

MONGODB: As a database is not a difficult database, his popularity should be attributed to his distributed and non-relational database, and simple operation, there are a large number of query instructions, but he has not supported the 32-bit system, and occupy a larger space.

And unlike the general database, his three elements are databases, collections, documents , and of course, databases, tables, and rows in relational databases. And, before use (Window System only, Mac and so on money to buy again) need to be in the drive letter Mogodb/bin/mongod.exe and Mongo.exe Open, knocking the blackboard This is the focus of operation, and, There is also an empty DB folder under the direct drive letter to store the data.

Later, I learned that node can create a back-office project, fumbling with the express framework to make a personal system, EXPRESS-E Pro Create Pro file directory structure,

1 Pro2|----bin3| |----www4|5|---- Public6| |----Images7| |----JavaScript8| |----stylesheet9|Ten|----Router One| |----Index.js A| |----Users.js -| -|----View the| |----Index.ejs -| |----Error.ejs -| -|----app.js

Of course, express also needs to carry on the NPM install download, although the page is not perfect but also has been perfect, The Ejs file of the page is also from the original Index.ejs to now have a simple login registration message, and so on, although the data is I write the fake data, but also I use the node. JS link database, and then using MongoDB query or write code to browse and write, and the database console code to view the With a little effort, I used his visualizer "V3 little Rocket" to operate.

--------------------------------------------------------------------------------------------

In the following understanding, it is found that node. js is not very suitable as a purely background, and java,php this mature language, he has a certain flaw, such as the inability to make full use of the CPU, and he is single-threaded, a part of the possibility will crash. But he also good, high concurrency scenario is very practical, because of his non-blocking I/O mechanism, very suitable for the large number of Ajax requests, and he and the front-end JS cooperation is very good, let me a front-end personnel also have access to the background of the language.

Although node. js appears not a few years ago, things are relatively new, but he as a very harmonious background with JS cooperation, coupled with the very useful NPM, can speed up our code development speed.

But to say node fire, I think otherwise, and for faint feel this is the illusion, although node with really very happy, also relaxed the code time. However, for now, node is quite new, but also in the state of reclamation, want to let him really fire up, it may take a little time. And he fire up the reason, presumably, the front-end comrades were "suppressed" by the backstage, Ha ha, finally have the chance to turn over, seize the opportunity to start learning, of course, can not deny node and front-end contact is really harmonious, and the contact MongoDB This database is not very difficult.

(PS: Do the project and it does not fire what relationship Ah, the project to the best level to make, bug debugging good, I think it is very good, haha ha)

Talk about node. js, which has been studying for some time recently

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.