= Run environment + JavaScript library node. js attribute
The asynchronous and event-driven APIs of the node. JS Library are all asynchronous and non-blocking. It mainly refers to node. JS-based servers that do not wait
. response.end(); // When we create the server, we have to explicitly connect the HTTP server to // a port. Standard HTTP port is 80, so we'll connect it to that one.}).listen(80);// Output a String to the console once the server starts up, letting us know everything// starts up correctlyconsole.log("Random Number Generator Running...");
Put the above code into a file named "random. js. To start the application and run it (to create an HTTP s
fact, the above content, most of the node. JS books are introduced. After a basic understanding of node. js, we can write some Hello World programs:
Build an HTTP server and return Hello, world. (Use HTTP module)
Reads a TXT file and displays the contents to the command line. (using FS module)
Wait a
. JSON in interactive mode
NPM adduser generates users on the node repo website through interaction
NPM publish can publish the package. If necessary, update the version number in package. JSON and re-publish.
NPM unpublish can unpack
3.3 debugging
3.3.1 node debug
Node debug script. js can be debugged under the comman
, once the socket instance is taken, you can use Net.socket to do whatever you want. I listened to the data event to receive the server-side information and listened to the close event to exit the process. Net. The specific API for the socket, refer to Https://nodejs.org/api/net.html#net_class_net_socket.Run the sampleStorytelling in a word, then clapped, ah ha, can run. By executing "
Use Meteor with Node. js to compile a real-time chat application example, meteornode. js
I often see Derby. the framework for js comparison is Meteor. js. similar to Derby, it can also update views in real time on multiple clients, although it may be a little different from
possible scenario is to control direct http access to Node. js web Services. However, you can use your own services or block them by using the firewall.Another reason is that the proxy method is a solution on the network application layer after all, and it is not very convenient to directly obtain and process data that interacts with the client http, for example, keep-alive, trunk, or even cookie processin
automated shell scripts, the synchronization method may be more useful. In most cases, the synchronization method will have an important impact on the performance, because it will block the event loop.
Child_process.spawn (), child_process.fork (), child_process.exec (), and child_process.execFile () are asynchronous APIs. Each method generates a ChildProcess instance, and this object implements Node. the EventEmitter
Stream is a very important module in node. js and is widely used. A stream is a readable, writable, or both readable and writable interface through which we can interact with disk files, sockets, HTTP requests, and enable the ability to move data from one place to another.All streams implement Eventemitter interfaces and have the ability to transmit events to feed the state of the stream. For example, when
server, so I also need to hear a port (in the example 54321). In addition, I will continue to send data to the server, so with setinterval started a periodic timer, loop send a string array of messages inside.The SetInterval is a method provided by the global object of node. js to start a recurring timer with the following prototype:setInterval(cb, ms)The first parameter is the callback function that execu
network application is the processing efficiency of I/O. Due to the limitations of hardware and network, the speed of I/O is often fixed, how to deal with more customer requests in this premise, and improve the efficiency of CPU usage becomes the biggest problem for the developers. Thanks to the event-driven programming model, node. JS uses a single event loop thread to process customer requests, assigning
1. IntroductionJavaScript is a script run in the browser, it is simple, lightweight, easy to edit, this script is usually used for front-end programming of the browser, but a developer Ryan discovered that the front-end scripting language can run on the server, a storm sweeping the world began.node. JS is a platform built on the chrome JavaScript runtime to easily build responsive, easy-to-scale Web applications.
); }else{Console.log (' StatusCode-%d ', res.statuscode); Process.exit (1); }}req.on (' Error ', handleError); Req.on (' response ', handleresponse);Using node. js To do some small experiments, gadgets or more convenient, it built up a lot of modules, such as http,crypto(encryption), easy to use.One thing to note is that the Okvoice API, the data passed in wh
more difficult,But the good news is that there are many libraries, such as async, that specialize in solving asynchronous programming problems, see Section 6.2.2.Let's look at how to read a file asynchronously in node. js, here's an example:Readfile.jsvar fs = require (' FS ');Fs.readfile (' file.txt ', ' utf-8 ', function (err, data) {if (err) {Console.error (ERR);} else {Console.log (data);}});Console.lo
task, nodejs the task to the line pool asynchronous processing, efficient and simple, so node. JS is suitable for processing I/o-intensive tasks, but not all tasks are I/o-intensive tasks, when encountering CPU-intensive tasks, is only CPU-based operations, For example, to the data encryption (node.bcrypt.js), data compression and decompression (Node-tar), then
originally an open source project by Ryan Dahl, which was later noticed by Joyent company. Joyent Company willRyan Dahl was recruited, so now node. JS is managed and maintained by Joyent company. Despite the time it was born (2009years) is not long, but it has formed a huge ecosystem around it. node. JS has a strong a
OnClose triggered when the connection is closed
Let's take a full look at the WebSocket API, which is actually very simple, and here are all the APIs:
1234567891011121314151617181920212223
[Constructor (in Domstring URL, in optional domstring protocols)] [Constructor (in Domstring URL, in optional domstring[] protocols)]interface WebSocket { readonly attribute domstring URL; Ready state Const unsigned short connecting
Reprinted: http://sd.csdn.net/a/20110617/299900.html
Guidance:Node is a server.Javascript interpreter, which will change the concept of how the server should work. It aims to help programmers build highly scalable applications and write programs that can process tens of thousands of concurrent connections to oneThere is a connection code for the physical machine. This article explores what problems node. js
At present, node. JS is very popular in front page development, it is a set of JavaScript toolkit to write high-performance Web server, in this article, will lead you beginners to introduce the basic knowledge of Node JS, This article is required to read for readers with certain JavaScript and other development languag
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.