Export in files

 two commands

require(file path) in the receiver

module.exports in the sender

in the export file

module.exports=123;

in the inport file

let val=require("./export");
console.log(val);


objects can be sent as

export
const sum=(a,b)=>a+b;
const mul=(a,b)=>a*b;
const g=9.8;
const pi=3.14;
let obj={
    mul:mul,
    sum:sum,
    g:g,
    pi:pi
}
module.exports=obj;

inport

let val=require("./export");
console.log(val.g);
console.log(val.pi);
console.log(val.sum(2,3));
console.log(val.mul(4,5));

they can also be sent as

module.exports={
    mul:mul,
    sum:sum,
    g:g,
    pi:pi
}


OR

module.exports.sum=(a,b)=> a+b;
module.exports.mul=(a,b)=> a*b;
module.exports.g=9.8;
module.exports.pi=3.14;

OR


exports.sum=(a,b)=> a+b;
exports.mul=(a,b)=> a*b;
exports.g=9.8;
exports.pi=3.14;

Comments

Popular posts from this blog

DATABASE RELATIONSHIPS

ROUTING (GET /) home route

Query Strings