Node.js Local Module



Node.js Local Module:

Node.js also facilitates its users to create their own modules using export keyword. Local modules are the user-defined modules which are created locally in a Node.js application. These local modules can also be mexican steroids online packaged and distributed via NPM.

  • Exports:

The module.exports object is a special type of object which is used to expose a function, object or variable as a module in Node.js.

➔   Creating a Local Module:

 

  • Create a module in a separate JavaScript file.
  • Assign the object of the module to exports.

 

  • Including a Local Module:

To include a local module in an application, Node.js require() function with the path of the module is used.

 

Syntax:

var variable_name = require(‘module_path’);

Example:

 Module: mod.js

 var mod = {

msg: function (msg) {

console.log(‘Msg: ‘ + msg);

},

};

module.exports = mod

 

Application: hello.js

 var hello = require(‘/home/Desktop/modu.js’);

hello.msg(‘HELLO’);

OUTPUT:

 Msg: HELLO

Tags: ,
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!

https://bridgejunks.com/ https://crownmakesense.com/ https://brithaniabookjudges.com/ https://hughesroyality.com/ https://rhythmholic.com/ https://bandar89.simnasfikpunhas.com/ https://www.100calshop.co.il/products/thailand/ https://myasociados.com/ https://solyser.com/ http://konfidence.cz/ https://muscadinepdx.com/ https://bandar89.parajesandinos.com.ve/ https://goremekoop.com/ https://oncoswisscenter.com/ https://www.turunclifehotel.com/bandar89/ https://www.houseofproducts.biz/ https://taimoormphotography.com/
BIJI18 BIJI18 BIJI18