Discover node js modules tutorial, include the articles, news, trends, analysis and practical advice about node js modules tutorial on alibabacloud.com
application into multiple modules to improve the reusability of the code. 1. How do I use the module?The use of modules in node is very convenient, and in JavaScript code you can directly use the global function require () to load a module.In just "Hello world" example, require ("http") can load the System preset HTTP module; The module name begins with "./", a
code test (Rpel command action), just as you would write code tests in the browser's console.4. Node module built-in modules (node environment is inherently provided): http (createserver ...), FS (Writefilesync, readfilesync), url ... Custom Modules : our own defined modulesIn the
and writing the database. Therefore, for javascript, it is best to use the callback function. Who will accept this callback? A server object!
The Code is as follows:
Var http = require ("http ");Http. createServer (function (request, response ){Response. writeHead (200, {"Content-Type": "text/plain "});Response. write ("Hello node. js? 6.1.3 ");Response. end ();}). Listen (8888 );
General development We all use thinkphp+bootstrap+jquery and so on.
node. JS is generally responsible for what, read some information on the Internet, generally understand.
But who can talk about specific applications. He appeared to solve the problems of the past?
What convenience can I use him to bring me?
Thanks
Excuse the novice.
Reply content:
General development We all use thinkphp+bootstrap+jque
-time responsibility for Node development.
In July 2011, Node launched the Windows Edition with Microsoft's support
At the end of January 2012, Ryan Dahl turned his head to Isaac Z.schlueter and turned to some research projects.
In December 2014, many of the heavyweight node developers were dissatisfied with Joyent's management of
. get ('/', function (req, res) {res. send ('hello, this is our first nodejs Project');}); app. listen (0, 8080 );
3.3 run the index. js File
node index.js
3.4 access through a browser
Enter the following address in the browser to access the web site we just set up.
127.0.0.1: 8080
4. Use Webstorm to build a Node. js w
refers to a Non-core module and is not a path-type identifier. It is a special kind of file module, which may be a file or package form. This type of module lookup is the most time-consuming and the slowest in all ways.2). File positioningFrom the optimization strategy of cache loading, the process of path analysis, file location and compile execution is not needed in two times, which greatly improves the efficiency of loading modules again. However,
Notes from the node. JS Development Guide ByvoidImplementation process: Https://github.com/ichenxiaodao/express-example5th chapter Web Development using node. jsZero-based implementation of a micro-blogging system with node. js, including routing control, page templates, dat
call when the main thread loops back to the event. This process is called the event loop , as shown in:This diagram is the whole node. JS operating principle, from left to right, top to bottom, node. js is divided into four layers, the application layer , theV8 engine layer , theNode API layer , and the libuv layer,
say that the backend does not involve database operations? This is not worth mentioning in comparison with the frontend DOM compatibility. What other folder and file operations do you think of as a special array operation. So you can be angry!
Okay, let's get some substantive content. Node. js is originally an http server and needs to interact with the front-end. Therefore, there are two objects: request a
in the Node kernel: The Event listener in http. ClientRequest was not released. (The patch that finally fixes this problem has only two but crucial letters ). This painful experience prompted Lloyd to write a tool that can help find memory leaks.
Memory Leak locating Tool
There are already many easy-to-use and constantly enhanced tools to locate the memory leakage of Node.
Crawl target: That's my own blog: http://www.cnblogs.com/ghostwu/Features that need to be implemented:Crawl Blog All article title, hyperlinks, article summaries, release timeLibraries that need to be used:node. js comes with the HTTP libraryThird party libraries: Cheerio, this library is used to handle the DOM node, his usage is almost identical to jquery usage, so with this tool, writing a crawler is very
. JS:201 ThrowE//Process.nexttick error, or ' Error ' event on first tick^Error:uncaught, unspecified'Error' Event. At Eventemitter.emit (events.js: -: the) at Object.5:9) at Module._compile (module.js:441: -) at Object. JS (module.js:459:Ten) at Module.load (module.js:348: to) at Function._load (module.js:308: A) at Array.0(Module.js:479:Ten) at Eventemitter._tickcallback (
The examples in the previous tutorial can be separated from the nodejs directory dependency, that is, they can be executed at any location. The examples and compiling environments in this section must be placed under the nodejs directory, this is because the path is involved. To install an external module, we first need to install an external module, which is FelixGei... SyntaxHighlighter. all ();
The examples in the previous
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
What is node. js
node. JS is a JS operating environment built on the Chrome browser V8 engine
Can parse and execute JS code
You can run the JS code from the brows
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
When it comes to components, JavaScript does not have this feature. Many functions of Javascript in the past were implemented by different vendors. Components have the following features:
. JavaScript does not have a module system. There is no native support for confined scope or dependency management.
. JavaScript does not have a standard library. There are no file system APIs in the core library, but these will be available after html5 :).
. JavaScript does not have a standard API.
. JavaScrip
own grammar, using the V8 engine, so is JS. V8 engine parsing JS, the efficiency is very high, and V8 a lot of things are asynchronous. Node is the V8 of some of the functions of the self-rewriting (others have done, they stand on the shoulders of giants), transplanted to the server.2) There is no web container, that is, after the installation configuration is c
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.