Две вещи.
Во-первых, вы никогда не вызываете свою анонимную асинхронную функцию.
Во-вторых, ваш экспорт находится в области действия этой функции, поэтому он никогда не устанавливается. Поэтому ваше требование возвращает пустое содержимое '{}' файла module.export.
Попробуйте что-то вроде этого.
const mongoose = require('mongoose');
module.exports = async ()=> {
await mongoose.connection.on('connected', ()=>{
const gridfs = require('mongoose-gridfs')({
collection: 'sharedfiles',
model: 'SharedFiles',
mongooseconnection: mongoose.connection
});
global.sharedfile = gridfs;
return gridfs;
});
}
Затем ваш экспорт предоставляет асинхронную функцию (обещание) для требуемого кода. Вы вызываете его с помощью ()
и используете .next
для обработки возвращенного результата.
require('path to above file') ()
.next(
function (gridfs) {
console.log (gridfs)
} )
.catch (...)
Или вы можете потребовать это, а затем вызвать его позже.
const getGridFs = require('path to above file')
...
getGridFs ( )
.next (gridfs => {console.log(gridfs)})
.catch (error => {console.error(error)})
Будьте терпеливы: вы поймете это.
This isn't easily explained in a StackOverflow post, particularly since proving it to you will involve a number of detailed steps. However, what you're describing is a common question and there's a number of thorough explanations. See here and here; I like #2 very much and have used it before.
There's Mathematica code at Wolfram MathWorld: Bézier Curve Approximation of an Arc, which should get you started.
See also: