- 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().
- Aptana Studio Beginner's Guide
- RCNP實驗指南:構建高級的路由互聯網絡(BARI)
- CorelDRAW X6 中文版圖形設計實戰從入門到精通
- 5G承載網網絡規劃與組網設計
- Web Application Development with R Using Shiny
- 局域網組建、管理與維護項目教程(Windows Server 2003)
- 2018網信發展報告
- VMware NSX網絡虛擬化入門
- React Cookbook
- 工業互聯網創新實踐
- Getting Started with Memcached
- 數字王國里的虛擬人:技術、商業與法律解讀
- 區塊鏈技術與應用:打造分布式商業新生態
- Microservices Development Cookbook
- 趣話通信:6G的前世、今生和未來