1

I have downloaded jsfeat from here, and unzipped the downloaded file.

Inside the directory, I wrote the following:

require("./build/jsfeat.js");
var matrix = new jsfeat.matrix_t(2,2, jsfeat.U8_t | jsfeat.C1_t);
matrix.data[1] = 4; 
console.log(matrix.data[1]);

I ran the program as follows:

$ node matrix.js

But, got the following error:

/Users/abc/Desktop/JavaScript/inspirit-jsfeat-59cc928/matrix.js:2
    var matrix = new jsfeat.matrix_t(2,2, jsfeat.U8_t | jsfeat.C1_t);
                     ^

ReferenceError: jsfeat is not defined
    at Object.<anonymous> (/Users/abc/Desktop/JavaScript/inspirit-jsfeat-59cc928/matrix.js:2:19)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:136:18)
    at node.js:972:3

Why is that? How can I solve the issue?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385

1 Answers1

5

You need to assign the imported module to a variable:

var jsfeat = require("./build/jsfeat.js");

If you prefer you could install the module with NPM to save downloading it manually:

$ npm install jsfeat

The module will be saved to ./node_modules/jsfeat. You can then require it with var jsfeat = require('jsfeat').

joews
  • 29,767
  • 10
  • 79
  • 91