Node Modules
Intro
Node allows you to use code from other files. This is called ‘requiring’ or ‘importing’, and gives you the ability to share functions, variables, and logic between multiple files. Node also provides a few conveniences, such as a node_modules
folder where you can easily reference modules, and a few built-in modules, like fs
for accessing the file system and http
for creating HTTP servers. Modules can also be downloaded from NPM.
Suggested Learning
- Node Modules Tutorial
- Modularity in Node - Just that section, although you should read it all 😉
- Node Docs on Modules - Read until ‘Accessing the Main Module’
- Loading Modules from
node_modules
Folder
Requirements
- Create a project with two files:
index.js
andstringGames.js
; - Create and export a function from
stringGames.js
which takes a string input and reverses it (eg: ‘Alex’ -> ‘xelA’) - Create and export a function from
stringGames.js
which takes a string input and uppercases it and adds a bang (!) to the end (eg: ‘Alex’ -> ‘ALEX!’) - Create and export a default function from
stringGames.js
which takes a string input with text and a string input for an emoji and adds the emoji input to the front and the end of the string (eg: ‘Alex’ and ‘🤓’ -> ‘🤓Alex🤓’). - Have
index.js
require all of the functions fromstringGames.js
, including the default. Have it run all of the functions andconsole.log
them. - Upload your work to a Github repository and post it on the
#requirements
Discord channel to show you have completed it.
Extra Learning
- Learn You Node - There is a section specifically for modules
- Node Modules - A video tutorial on modules.
This list is by no means complete. Feel free to add an issue or put in a pull request to update it.