package.json
.index.js
.myModule.js
Pour installer un module à l’aide de NPM : npm install chalk@4
{
"name": "new_proj",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \\"Error: no test specified\\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"chalk": "4.1.2"
}
}
module.exports.title = "mon premier module JS";
module.exports.add = function (a, b) { return a + b; };
module.exports.subt = (a, b) => { return a - b; };
const { title, add, subt } = require("./myModule");
const chalk = require("chalk");
console.log(chalk.red(title));
console.log(chalk.green(add(1, 2)));
console.log(chalk.blue(subt(3, 1)));
mon premier module JS
3
2