DEV Community

Bipon Biswas
Bipon Biswas

Posted on

2 2

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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more