'Node unable to find local module

I was testing a very simple module to see if it works and keep on getting an error stating that node cannot find my module.

//mymodule.js
greeting = 'hello'
module.exports = greeting;

// main.js
const s = require('exportsPractice\mymodule.js');
console.log(s);

The error I get is shown here



Solution 1:[1]

Try using:

const s = require('./exportsPractice/mymodule.js');

And make sure the path is correct.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Madhan S