In-depth understanding of the node. js http module, and in-depth understanding of node. js
The http module is mainly used to build an HTTP server and client. The HTTP module must be called to use the http server or client functions.
Create a server
Var http = require ("http"); var url = require ("url"); // create a ser
Console command in detail to make debugging JS code easierFirebug is a powerful tool for web development, which can greatly improve work efficiency.But it's not easy to get started. I have translated a "Firebug Getting Started Guide" and introduced some basic usage. Today, continue to introduce its advanced usage.===================================Firebug Console
to the original exports}) (module, module. exports); return module. exports ;}
So naturally:
Console. log (module. exports === exports); // true // Therefore, the operation of exports is module. exports.
The exports in Node. js is a copy of the module. exports reference. You can use exports to modify the attributes exported from the current
title of the parameter will be used as the prefix for the output when it is output.15, Console.clear ()Emptying the consoleSecond, using the console debugging JS script instance1, Console.log ()The simplest method is Console.log (), which can be used to replace alert () or document.write ().In addition, depending on the nature of the information, the console obj
This article mainly introduces Node. methods for securely calling system commands in js (to avoid injection security vulnerabilities). This article describes the security issues that may occur when connecting strings, for more information about how to use Node, see this article. js calls system commands to avoid common
, while an Http connection is different. an http request object is a readable stream, and an http response object is a writable stream.
By default, the stream is transmitted in the form of buffer, unless you set other encoding formats for it. The following is an example:
The code is as follows:
Var http = require ('http ');Var server = http. createServer (function (req, res ){Res. writeHeader (200, {'content-type': 'Text/plain '});Res. end ("Hello, Big Bear! ");});Server. listen (8888 );
, while an Http connection is different. An http request object is a readable stream, and an http response object is a writable stream.
By default, the stream is transmitted in the form of buffer, unless you set other encoding formats for it. The following is an example:
The Code is as follows:
Var http = require ('http ');Var server = http. createServer (function (req, res ){Res. writeHeader (200, {'content-type': 'text/plain '});Res. end ("Hello, Big Bear! ");});Server. listen (8888 );
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
folder containing the censority sub-folder will be generated in the readwords folder.
4. Create a New readwords. js file for testing (note that the Code console and function of the encapsulation module should not be written incorrectly)
var censor=require("censority");console.log(censor.getCensoreWorlds());console.log(censor.censor("Some very sad,bad and mad text"));censor.addCensoreWorld("gloomy");conso
follows:
Head-10 some.txt | node parser. js
For a Readable stream, we can also subscribe to its data and end events to obtain data blocks and receive notifications when the stream is exhausted, as in the typical socket example:
The Code is as follows:
Req. on ('connect ', function (res, socket, head ){Socket. on ('data', function (chunk ){Console. log (chunk.
Node. js checks for updates using the command line tool, and node. js command line
With the popularity of Node. js, it becomes easier to develop command line tools using Node.
Introduction:
JS Console you can see in Firefox firedbug or IE and Google's F12 debugging mode, these mainstream browser debugging mode of control can output some information, Some of your JS code tests can be entered directly in the console window and then run the view results, save the deployment of the project and r
Node. js and C can traverse the largest file in the folder and output the path, size, and node. js path.
Node. js
Traverse the maximum file in the folder and output the path, size
Implementation Code:
/* Traverse the maximum file
'\', which is also a problem discovered after the deployment is complete. Later, we found that path. basename was directly replaced (if the document was read less, it would suffer ). Adding 1 point to your liking for node. js. :)
3. redis cache frequently queries and rarely changes data.
Copy codeThe Code is as follows:GetCountAll: function (objFun ){Redis. get ('articles _ getcountall', function (err, rep
) + '\ n');} var warn = function () {writeerror (format. apply (this, arguments) + '\ n');} var error = function () {writeerror (format. apply (this, arguments) + '\ n');} var dir = function (object) {var util = require ('util'); process. stdout. write (UT Il. inspect (object) + '\ n');} var time = function (Label) {Times [label] = date. now ();} var timeend = function (Label) {var duration = date. now ()-Times [label]; exports. log ('undefined: nanm', label, duration);} var trace = function (La
[Node. js learning] -- (1) -- HelloWord, node. js -- helloword
Today, I practiced an entry-level case of nodejs, which is very lightweight and fast!
Official Website
Http://nodejs.org/download/
Download
Windows 7 64-bit download msi installation package:
Http://nodejs.org/dist/v0.12.0/x64/
information, namely General Information Console.info (), Error console.debug (), Warning Console.warn (), Error message Console.error ().For example, insert the following four lines in the Web script:
Console.info ("This is Info");
Console.debug ("This is Debug");
Console.warn ("This is warn");
Console.error ("This is Error");
When loaded, the console displays the following conten
Node. js crawlers crawl garbled data. node. js crawlers crawl garbled data.
1. Non-UTF-8 page processing.
1. Background
Windows-1251 Encoding
Such as Russian site: https://vk.com/cciinniikk
Shameful discovery is this encoding
Here we mainly talk about the problems of Windows-1251 (cp1251) encoding and UTF-8 encoding.
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.