I'm trying to use the Fuse.js library and display it's result through the terminal using Node.js, however, I can't seem to find a way to incorporate external libraries into my code.
I googled about it for a bit, and found that I need to add var foo = require("MyLibraryPath.js"); at the beginning, but after trying that I can't still access any function from that library.
I also tried to just copy and paste the whole library at the beginning of my code, but it throws an error.
My code so far looks something like this. This library is used to search through arrays and return the most similar items to the search you did in your array. I oversimplified it just so you can see where it stops working
var getFuse = require("fuse.js");
var fs = require("fs");
var arr = [
{item:"one"},
{item:"two"}
];
var options = {
//insert search options here
}
//In order to search, I need to put things like this
var fuse = new Fuse( array ,options);
//Here I insert what I want to search
var result = fuse.search("one");
However, when I open the terminal and execute
node myFile.js
I get
ReferenceError: Fuse is not defined`
at Object.<anonymous> (/Users/myFile.js:21:12)
at Module._compile (internal/modules/cjs/loader.js:707:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
at Function.Module._load (internal/modules/cjs/loader.js:536:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
at startup (internal/bootstrap/node.js:308:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:878:3)
Am I calling the library incorrectly? Is it not possible to load external libraries, I tried both using the external link and downloading the library and calling it locally, but it gave me the same error.
getFuse, notFuse, in yourrequire()line.var fuse = new getFuse( array ,options);