LEARNING JAVASCRIPT - Trang 310

Module

Global Description

tls

No

Transport Layer Security (TLS) communication utilities.

tty

No

Low-level TeleTYpewriter (TTY) functions.

dgram

No

User Datagram Protocol (UDP) networking utilities.

url

Yes

URL prasing utilities.

util

No

Internal Node utilities.

vm

No

Virtual (JavaScript) Machine: allows for metaprogramming and context creation.

zlib

No

Compression utilities.

It is beyond the scope of this book to cover all of these modules (we will discuss the

most important ones in this chapter), but this list gives you a starting point to look

for more information. Detailed documentation for these modules is available in the

Node API documentation

.

Finally, there are npm modules. npm modules are file modules with a specific naming

convention. If you require some module

x

(where

x

is not a core module), Node will

look in the current directory for a subdirectory called node_modules. If it finds it, it

will look for

x

in that directory. If it doesn’t find it, it will go up to the parent direc‐

tory, look for a module called node_modules there, and repeat the process until it

finds the module or reaches the root. For example, if your project is located in /home/

jdoe/test_project, and in your application file, you call

require('x')

, Node will look

for the module

x

in the following locations (in this order):

/home/jdoe/test_project/node_modules/x

/home/jdoe/node_modules/x

/home/node_modules/x

/node_modules/x

For most projects, you’ll have a single node_modules directory in the application root.

Furthermore, you shouldn’t add or remove things from that directory manually;

you’ll let npm do all the heavy lifting. Still, it’s useful to know how Node resolves

module imports, especially when it comes time to debug problems in third-party

modules.
For modules that you write yourself, do not put them in node_modules. It will work,

but the point of node_modules is that it’s a directory that can be deleted at any time

and re-created by npm from the dependencies listed in package.json (see

Chapter 2

).

286 | Chapter 20: Node

Liên Kết Chia Sẽ

** Đây là liên kết chia sẻ bới cộng đồng người dùng, chúng tôi không chịu trách nhiệm gì về nội dung của các thông tin này. Nếu có liên kết nào không phù hợp xin hãy báo cho admin.