Zhanhailiang Date: 2014-11-23Principle:
Parse the request URL to the corresponding file path;
Determine if the file exists;
If present, read the file content output;
Realize:varPath=Require(' path '),Fs=Require(' FS ');Require(' http ').Createserver(function(Req,Res) { //Parse file path, default to the current directory as the root directory to find files //This can be done by configuring the root value to find files for the relative root directory varFile=Path.Nor
Original address: http://my.oschina.net/yushulx/blog/309413Catalogue [-]
Installation
Service side
Client
Reference
Installation?
1
npminstallws
Service sideServer.js?
12345678
var WebSocketServer=require(‘ws‘).Server,wss=newWebSocketServer({port:8080});wss.on(‘connection‘,function(ws){ws.on(‘message‘,function(message){console.log(‘received:%s‘,message);});ws.send(‘something‘);
Node. js remotely connects to the MongoDB database server on another host
My MongoDB is installed in linux.
First, add a user
1. First, run the terminal command line on the MongoDB server host and enter
Mongo
2. Enter use admin to access the user management database.
3. db. addUser ("username", "password"); here, the u
than the HTTP protocol.
OpenSSL generates a certificate fileAs long as the Git client is installed, there will be OpenSSLDetect if OpenSSL is installedOpenSSL version-aNext, start generating the certificate:#1#2, generate CSR certificate signature via private key -new-key Privatekey.pem- Out certrequest.csr#3-req- in Certrequest.csr-signkey privatekey.pem-out Certificate.pemAfter executing the third command you will see: Signature ok表示生成成功,最终看到如下三个文件
PRIVATEKEY.PEM: Private key
Client-clients, commonly referred to as browsers, can request data from the server via the HTTP protocol.
Server -a server-side, generally referred to as the Web servers, can receive client requests and send response data to the client.
Business-service layer, which handles applications through Web servers, such as interacting with databases, logical opera
Nodejs is actually a JavaScript execution environment.To create a new file Server.js, enter the following code:var http = require (' http 'var server = Http.createserver (function(req, res) { Res.writehead ($, {' Content-type ': ' Text/plain '}); Res.end (' Hello world\n ');}); Server.listen (1337, ' 127.0.0.1 '); Console.log (' Server running at http://127.0.0.1:1337 ');The console goes to the direct
In mysql-cluster, the SQL node (master) and the Independent mysql server (slave) are used to copy (troubleshoot) The cluster environment: www.2cto.com mysql-cluster 7.2.8 (mysql 5.5.27; ndb 7.2.8) 192.168.55.11 mgm node (nodeid = 1) 192.168.55.10 data node (nodeid = 2) +
Description (2017-5-2-10:27:03):1. Need to install node,http://nodejs.cn/download/2. After installation, enter node-v in cmd to view the version.3. Code Foo.js:Attention:(1) Http.createserver two parameters, Req.url instead of Res.url, finally must res.end ()!(2) Server.listen is not listener. 3000 is the port, name it casually. The following is the routing address of their own computer, CMD in the Ipconfig
1. Prepare a folder for the project2. Create a server.js file under the root directory3. The file code is as followsvar http = require ("http");Http.createserver (function (request,response) {Response.writehead (200,{' content-type ': ' Text/plain ');Response.End ("Hello world\n")}). Listen (8080);Console.log ("Server running at http://127.0.0.1:8080/")4. Open the project directory with the command line execute the
Note:
1. To save the hello. js program file as a UTF-8 hello. js file, use notepad.
2. Chinese encoding must be supported in the output webpage.
Res. write ('
Now we use node. js to create a small www server.
Console. log ('hello') console. log ('Hello % s-> % d
This is the real reason we learn node. js, Server!1, create a new index.js write downvar Myhttp=require (' http '); Myhttp.createserver (function(req,res) {res.writehead (200,{') Content-type ': ' Text/thml '}); Res.write (' ); Res.write (' ); Res.end (2. Open cmd and run node Index.js3. Open the browser input http://
Let Http=require ("http");//introducing the core HTTP moduleLet Fs=require ("FS"); let mime={ '. js ': ' Application/javascript ', '. css ': ' Text/css '}//Create a function that Req represents the client and res represents the server writable streamLet listener= (req,res) ={//Res is a writable stream with write and end if(req.url=== "/"){ //Set EncodingRes.setheader (' Content-type ', ' tex
This article mainly introduces how to easily create nodejs servers (9): to implement non-blocking operations, this series of articles will teach you to create a complete server step by step, for more information, see the response object (obtained from the server's callback function onRequest (), which is routed to the request handler. Then, the handler can use the functions on the object to respond to the request.
Modify
This article mainly introduces how to easily create nodejs servers (9): to implement non-blocking operations, this series of articles will teach you to create a complete server step by step, for more information, see the response object (obtained from the server's callback function onRequest (), which is routed to the request handler. Then, the handler can use the functions on the object to respond to the request.
Modify
This article mainly introduces how to easily create a nodejs server (6): to respond, we will then transform the server so that the request processing program can return some meaningful information, for more information, see modify the server so that the request processing program can return meaningful information.
Let's take a look at how to implement it:
1. let
Open service:The code is as follows:varHTTP = require ('http'); Http.createserver (function (request, response) {//Send HTTP Header//HTTP Status value: 200:ok//content Type: Text/plainResponse.writehead ( $, {'Content-type':'Text/plain'}); //Send response data "Hello World"Response.End ('Hello world\n');}). Listen (8888);//The terminal prints the following informationConsole.log ('Server running at http://127.0.0.1:8888/');
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.