- Learning Node.js Development
- Andrew Mead
- 272字
- 2021-06-30 18:56:45
Module basics
In this section, you will finally learn some Node.js code, and we'll kick things off by talking about modules inside Node. Modules are units of functionality, so imagine I create a few functions that do something similar, such as a few functions that help with math problems, for example, add, subtract, and divide. I could bundle those up as a module, call it Andrew-math, and other people could take advantage of it.
Now, we'll not be looking at how to make our own module; in fact, we will be looking at how we can use modules, and that will be done using a function in Node, called require(). The require() function will let us do three things:
- First, it'll let us load in modules that come bundled with Node.js. These include the HTTP module, which lets us make a web server, and the fs module, which lets us access the filesystem for our machine.
- We'll be able to use prewritten libraries to handle complex problems, and all we need to do is implement require() by calling a few methods.
- We will use require() to require our very own files. It will let us break up our application into multiple, smaller files, which is essential for building real-world apps.
If you have all of your code in one file, it will be really hard to test, maintain, and update. Now, require() isn't that bad. In this section, we'll explore the first use case for require().
- 黑客攻防實(shí)戰(zhàn)技術(shù)完全手冊(cè):掃描、嗅探、入侵與防御
- Building E-commerce Sites with VirtueMart Cookbook
- 物聯(lián)網(wǎng)識(shí)別技術(shù)
- Hands-On Chatbots and Conversational UI Development
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- The Kubernetes Workshop
- 設(shè)備監(jiān)控技術(shù)詳解
- 一本書讀懂物聯(lián)網(wǎng)
- Selenium WebDriver 3 Practical Guide
- 華為HCIA-Datacom認(rèn)證指南
- Web用戶查詢?nèi)罩就诰蚺c應(yīng)用
- 圖解物聯(lián)網(wǎng)
- 現(xiàn)場(chǎng)綜合化網(wǎng)絡(luò)運(yùn)營(yíng)與維護(hù):運(yùn)營(yíng)商數(shù)字化轉(zhuǎn)型技術(shù)與實(shí)踐
- 智能物聯(lián)網(wǎng):區(qū)塊鏈與霧計(jì)算融合應(yīng)用詳解
- 趣話通信:6G的前世、今生和未來(lái)