provided by HTML5. It uses a "handshake" to implement communication between the client and the server. The real-time performance is good and the header carried is small. Currently, the supported browsers are as follows:
Client JavaScript code:
Var socket = io. connect ('2017. 0.0.1: 8181 '); // send data to the server socket. emit ('fromwebclient', jsonData); // receives data from the server socket. on ('pushtowebclient', function (data) {// do something .});
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 query is a near duplication of the correspondin
mode. Its objects include addListener, on, once, removeListener, removeAllListeners, emit, and other basic event listening modes.
First, let's look at an example:
Var events = require ("events"); var emitter = new events. eventEmitter (); // creates an object for the event listener // listens to the event some_eventemitter.on ("some_event", function () {console. log ("event triggered, call this callback f
If you're writing the node. JS code, Node-inspector is a must-have option, much better than node. JS's built-in debugger. It's similar to Chrome's JavaScript debugger.To install with NPM:$ npm install -g node-inspectorThen you need to connect to
){Callback (err, null );});}
Task 3:
Save rss to a file and return an error through callback.
Copy codeThe Code is as follows:Var saveRss = function (data, callback ){Fs.writeFile('rss.txt ', data, 'utf8', function (err ){Callback (err );});}
Integration:
Copy codeThe Code is as follows:Getrssaddress('ssss.txt ', function (err, data ){If (err ){Console. log (err );Return;}GetRss (data, function (err, data
Promise/A specifications, when. js, is targeted at such problem domains.
Let's take a look at the transformed code.
Task 1:
The Code is as follows:
Var getRssAddress = function (path ){Var deferred = when. defer ();Fs. readFile (path, {encoding: 'utf8'}, function (err, data ){If (err) deferred. reject (err );Deferred. resolve (data );});
Return deferred. promise;}
Task 2:
The Code is as follows:
Var getRss = function (url ){Var deferred = when
1 //Create App.js page2 //One: page code3Console.log ("Log Information");4 //Execute (node app.js) in the page this file will see the log message in the console: "Log Information"5 //execute in another way: node App.js 1>info.txt
Module stability: 5-lockednode has a simple module loading mechanism. in node, files and modules are one-to-one. for example, foo. javascript loads the circle in the same folder. js module. foo. js content: [javascript] lt; SPANstyle quot; FONT -...
Module)
Stability: 5-locked
Node has a simple module loading mechani
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 port = mongo. Connection. DEFAULT_PORT;Var serve
can edit and compile it in vs2013.Of course, you can also directly use the node-gyp build command to compile.The test js program is as follows: The Code is as follows:Var hello = require ('./hello ');Console. log (hello. hello ());Some problems were encountered, as shown below:1. C: \ Users \ Administrator.
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
This article mainly introduces node. the js entry-level instance helloworld describes node in detail. js simple output example helloworld implementation code and running method. If you need it, refer to the example in this article to describe node.
+ item ;}) ;}; str = str. replace (r2 ,''). replace (r4, '');/* asynchronously write to the target file */fs. appendFile (writePath, str, {encoding: 'utf8'}, function (err) {if (err) {throw err}; console. log ('complete ........ ');});};
Although the content is small, I still want to adapt to commomJS's modular programming, So I split the above module into ^ _ ^, file name: compress.
Detailed description of the use of require in node. js, node. jsrequire
The descriptions in the code comments are very clear, so there is not much nonsense here. The code is provided directly:
Copy codeThe Code is as follows:/* In node, you can use the require () function to load modules.* The require function uses a p
This article mainly introduces Node in Linux. the method for configuring MySQL or Oracle databases in js programs. By default, the Node environment has been assembled and we can use the npm package management tool for configuration. For more information, see
Mysql usageInstall the mysql module:
Run the command in the cmd command line of the installation root dire
properly, a build directory should be generated, and related files may be the vcxproj file of M $ Visual Studio, or Makefile, depending on the platform.BuildAfter Makefile is generated, we start to construct and compile:$ Node-gyp buildIt will be a real success when all compilation is complete! Check the build/Release directory. Is there a hello. node file below? That's right. This is the soap to be picked
installation ')
See http://www.dbpoo.com/sublime-text2-theme-sod/ for details
7. After the installation is complete, restart Sublime and press the shortcut key Ctrl + Shift + P. Enter install, select Install Package, and press Enter.
8. Enter nodejs and select Nodejs for installation (JavaScript NodeJs Snippets can be installed)
9. Create the test. js file and ent
file is index. js, and index. js will be loaded. If index. js does not exist, loading will fail.
Assume that the directory structure is as follows:
Package. json is defined as follows:
Copy codeThe Code is as follows:{"Name": "pack ","Main": "modA. js"}
At this time, require ('./folder') will return the modA.
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.