R
R
rd1002022-01-03 14:50:04
Node.js
rd100, 2022-01-03 14:50:04

How to include another file using require?

There is a file settings.jsin it

const sel = {
  user: 'Patron'
}
module.exports = sel

And another file from the same folder where we call
const { sel } = require('./settings')
console.log('user', sel)


Butsel -> undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2022-01-03
@rd100

replace:
module.exports = sel
with

exports.sel = sel;
// или
module.exports.sel = sel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question