Nodejs code snippets worth collecting. You can add them to your favorites and use them in subsequent work, if you are interested, you can refer to the following code snippets worth collecting for your reference:
1. For details about node. js static resource compression and caching, refer to: node. js creates a static
This article mainly introduces the node. js game sharing that allows multiple users to move their mouse online at the same time. This article provides the server and client code and running methods. For more information, see the recent project requirements, so I studied the websocket Implementation of nodejs, socket. io, which is a widely used framework of nodejs background applications websocket.
Preparat
This article mainly introduces Node. how to Use the domain module in js exception handling. The memory leakage problems are mentioned at the end of this article. It is worth noting that if you need a friend, you can refer to the domain module provided by NodeJS, it can simplify Exception Handling for asynchronous code. Before introducing this module, we need to first understand the concept of "domain. Simpl
This article mainly introduces Node. example of calling the mysql stored procedure in js. this article passes the test in the windows environment. This article also provides examples of creating a database, inputting data, creating a stored procedure, and calling a stored procedure, for more information, see the example below. it is only tested in windows and not in linux. If you have any questions, please
This article describes how to use socket in Node. js to create private chat rooms and public chat rooms. For more information, see:
In the previous article, we will introduce the use of Angular, Nodejs, and socket. i/O builds chat rooms and multi-user chat rooms. This article continues to introduce Node. use socket in js
example
Get started with Node. js development-use AngularJS
Getting started with Node. js Development -- using the jade template engine
Introduction to Node. js development-routing
This article mainly introduces node. socket. io broadcast messages. For more information, see socket. the io () server has a sockets attribute. The attribute value is all socket objects connected to the client. you can use the send method or emit method of this object to broadcast messages to all clients.
Io. sockets. send ("user commected );
Io. socket. emit ("login", names );
Case
Server. js code:
The
This article mainly introduces the node. js game sharing that allows multiple users to move their mouse online at the same time. This article provides the server and client code and running methods. For more information, see the recent project requirements, so I studied the websocket Implementation of nodejs, socket. io, which is a widely used framework of nodejs background applications websocket.
Preparat
users to enter a name is displayed. When the user input is complete, click the Confirm button, we can use the value parameter of the confirm method to obtain the value of the user name input box.
Other articles:
Getting started with Node. js Development -- introducing UIBootstrap
Getting started with Node. js devel
.-MysqlDB. js is used to provide user. js with the tool class for linking the database and the class for actually operating the database.-User. js is used to provide the Implementation Layer with an addition, deletion, modification, and query method for users, which is equivalent to an intermediate layer.-Node_modules is the dependent package required by nodejs.-
This article mainly introduces node. socket. io broadcast messages. For more information, see socket. the io () server has a sockets attribute. The attribute value is all socket objects connected to the client. you can use the send method or emit method of this object to broadcast messages to all clients.
Io. sockets. send ("user commected );
Io. socket. emit ("login", names );
Case
Server. js code:
The
Node. js is the best choice for Web application development.
The entry of a disruptive technology into the technology market is always a shock, but it is often abandoned. However, this is certainly not the case for Node. js. It is an open-source, cross-platform Chrome-based JavaScript runtime.
more importantly, it depends on the open source Library at the upper layer. Express + (mongo + mongoose) | (node-mysql + sequencee) CRUD development is also fast, more importantly, Node's asynchronous database I/O performance is much higher than that of Python.
Some people say that Node lacks a "mature" Big framework. In fact, this is related to the development ideas of the
module ):
The Code is as follows:
Npm install supervisor-g
Assume that the main portal of your Node. js program is app. js, you only need to execute the following command to start monitoring file changes.
The Code is as follows:
Supervisor app.
then string them together" of the Unix philosophy, plus NPM for the mutual dependence of the package is handled very well, So flexibility is actually one of node's selling points. In my personal view, node does not need a web framework such as "chatty" like Rails/django.
Disclaimer: The following comparisons may have a strong personal color
Places in node. js >
are not set to on, run chkconfig -- level 35 [your service name] on. Ubuntu Server may report some warnings, however, if you can change 3 and 5 of the services you want to set to on, other errors can be ignored (I think this is the system's own thing ).
After the configuration is complete, the Node project can be self-started on Linux. You can shutdown-r now to check whether the Node project can be self-st
, performance depends largely on the experience and focus of the development team, but node. JS has the following advantages:
Less Reliance
All requests for PHP applications must be routed through a WEB server to start PHP's interpreter to run PHP code. node. JS does not need these dependencies, and you will almost cer
Summary of console usage in node. js and node. jsconsole usage
Copy codeThe Code is as follows:// Create an app. js page// 1: Page codeConsole. log ("log information ");// Run the node app
) { if (error) { console.log(error.stack); console.log('Error code: '+error.code); } console.log('Child Process STDOUT: '+stdout);});
Normally, the spawn. js file is deleted.
The preceding two commands are simple commands for running processes. Finally, (Boss is always the final player). Let's take a look at the use of the fork method.Fork is actually used to execute processes. For example, spawn ("node
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.