This is a simple example of how to use CommonJS modules in Node.js.
To use this example, clone this repository and run the following command:
npm install
Then, you can run the main.js
file using Node.js:
node main.js
This will execute the code in the main.js
file, which imports the greetings
and bye
functions from the myModule.js
module using destructuring assignment, and then calls these functions with the argument "Alessandro".
This file imports the greetings
and bye
functions from the myModule.js
module using destructuring assignment, and then calls these functions with the argument "Alessandro".
This file defines two functions: greetings
and bye
. The greetings
function outputs a greeting message to the console that includes the message passed as an argument, while the bye
function outputs a farewell message to the console that also includes the message passed as an argument. These functions are then exported as properties of an object using the module.exports
statement.
This file specifies the name, version, description, entry point, scripts, author, and license of the example project. The serve
script runs a local HTTP server for development purposes.
Run with node src/main.js