import {Word} from '../models/word.js';
import wordnet from "en-wordnet";
import Dictionary from 'en-dictionary';
export const checkingWork = (req,res) => {
res.status(200).json({
message:"Route is working fine",
})
};
export const findWord = async(req,res,next) => {
try{
const to_find = req.params.id;
const res1 = await Word.findOne({"word":{$regex:to_find}});
if(!res1){
const dictionary = new Dictionary(wordnet['3.0']);
await dictionary.init();
const result = dictionary.searchSimpleFor(req.params.id);
res.status(200).json({
success:true,
result,
})
}
else{
res.status(200).json({
success:true,
message:"word found in the database",
res1,
})
}
}
catch(error){
next(error);
}
}
Here I am trying to find a word using en-dictionary module and wordnet but I am getting the error
TypeError: Dictionary is not a constructor
at findWord (file:///C:/Users/adi/dictionary/controllers/wordController.js:18:32)
I can't understand why I am getting this error and how to resolve it I am following their documentation by still can't figure out how to resolve the error and find the word. Can someone help me out as to how to fix this error.
the following is the link to en-wordnet and en-dictionary https://github.com/open-language/en-dictionary/tree/master/src