DEV Community

Bipon Biswas
Bipon Biswas

Posted on

Node Module Export

create a file like people.js

var people = ['sakib', 'tamim', 'bipon']

var a = 6;

function test(){
    console.log("test")
}

Enter fullscreen mode Exit fullscreen mode

Import into index.js file

const people = require('./people')
Enter fullscreen mode Exit fullscreen mode

Then run into terminal by node index.js. Showing blank {}

Alt Text

Update one line into people.js file

var people = ['sakib', 'tamim', 'bipon']

var a = 6;

function test(){
    console.log("test")
}

module.exports = people;
Enter fullscreen mode Exit fullscreen mode

Or

var people = ['sakib', 'tamim', 'bipon']

var a = 6;

function test(){
    console.log("test")
}
console.log(module)
// module.exports = people;

module.exports = {
    people: people,
    a: a,
    test: test
}
Enter fullscreen mode Exit fullscreen mode

Output

Alt Text

If console.log(module) then showing bellow output.

Command into terminal node people

Output

Alt Text

By default exports blank. exports: {}. That's why without export showing blank value.

Latest comments (0)