This article mainly introduces Node. this article describes the features and application scenarios of js. js's asynchronous IO, event loop and callback functions, single-thread, cross-platform features, and then summarizes its use scenarios. For more information, see Node. js should be one of the hottest technologies t
This article focuses on the method of creating the first application for node. js, as well as the introduction of five different scenarios. So that everyone can learn something, learn this, and then let's come and see this article.
First, let's try to create the first application:
Before we create the first "Hello, world!" app for node.
function supports the third form of path, which is similar to foo/bar, and resolves the path according to the following rules until the module location is found.
Built-in modules
If the node. js built-in Module name is passed to the require function without path parsing, the export object of the internal
install the Node. js external module.
Install Node. js on Debian
Since Debian 8 (Jessie), Node. js has been incorporated into the official software repository. Therefore, you can insta
supported. The documentation and demo code are not complete and there are not many users.
1. Implement Node. JS components using pure js(1) Run npm init in the helloworld directory to initialize package. json. The options are ignored by default.
(2) component implementation index. js, for
within our node. js app.
Here's an example for finding documents within a collection specifically in this case to find all female users.
// app.jsdb.users.find({sex: "female"}, function(err, users) { if( err || !users) console.log("No female users found"); else users.forEach( function(femaleUser) { console.log(femaleUser); } );});
Notice how our initial qu
": true
If you have used gcc, remember makefile. Similarly, gyp describes the compilation configuration through a file, which is binding. gyp, which is a json file that we are very familiar. Gyp is not the focus of our discussion, so binding. gyp will not be further explored. We only focus on the most important configuration items. The following is an example of a simple but complete binding. gyp file:
The Code is as follows:
{"Targets ":[{"Target_n
completed the setup, but you don't know if it can run correctly, let's write an example file to test it.
Create example. js in the C: cygwin directory
Input
Var http = require ('http ');
Http. createServer (function (request, response ){
Response. writeHead (200, {'content-type': 'text/html '});
Response. end ('Hello World');
}). Listen (8888 );
Console. log ('s
Ryan Dahl Development Node was originally designed to Nginx combine the non-blocking IO functionality with a highly encapsulated Web server. So node's original purpose is to be a high-performance Web server, so: node's HTTP module is also the core of the core.This article requires you to understand the pre-knowledge points:
HTTP protocol
Web request model: request → process → response
Strea
Talking about the timer in Node. js and talking about the timer in Node. js
Implementation of timer in Node. js
As mentioned in the previous post, timer in Node is not implemented throu
This article focuses on the definition and description of node. js, as well as 10 scenarios for node. js to let you know where node. js can be applied, and now let's look at this article.
First we need to know what
This article analyzes and explains node through several examples. the use of require in js is very detailed. Here we recommend that you provide a very clear description in the code comments. Here we will not talk nonsense about it. We will provide the Code directly:
The Code is as follows:
/* In node, you can use the require () function to load modules.* The r
operating system installation file (install the latest version)
Follow the prompts to go to the next step until the installation is successful. You can see (C: \ Program Files \ nodejs) in the default installation path. The default path can be modified during installation.
After the installation is successful, enter "node-v" in the "command prompt" to view the installation version. The installation is successful if the version is output.
NPM Introduc
": true
If you have used gcc, remember makefile. Similarly, gyp describes the compilation configuration through a file, which is binding. gyp, which is a json file that we are very familiar. Gyp is not the focus of our discussion, so binding. gyp will not be further explored. we only focus on the most important configuration items. The following is an example of a simple but complete binding. gyp file:
The code is as follows:
{"Targets ":[{"Target_n
the consumer, and the called consumer is idle.
There is a message queue in the Javascript runtime, and the message is associated with a callback function. When an event is triggered, if the event has a corresponding callback function, the message is added to the message queue.
Let's look back at what the event loop is. After the code starts to be executed, the function is pushed into the calling pipeline. In this example, the request is pushed into t
you have prepared all the materials required for subsequent module compilation. You need node-gyp and all its dependencies. You can use the following command to install node-gyp:
npm install -g node-gyp
In terms of dependencies, we need to prepare the following projects for Unix systems: • Python (version 2.7 is req
path.
Node. js Website: http://nodejs.org/
Enter the tar xf node-v0.4.7.tar.gz in the Command window, node-v0.4.7.tar.gz for your own version.
Enter the cd node-v0.4.7 in the Command window and press Enter.
Enter./configure in the Command window and press Enter.
Enter make
,getRecentActivity,getSubscriptions,getNotifications], function(err, results) {//This callback runs when all the functions complete});}
If you want to learn more about async. js, go to its GitHub page.
2. asynchronous
According to the design, Node. js is single-threaded. Based on this, the synchronization code will block the entire application. For
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
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.