Search code examples
javascriptnode.jsmongodbmongoosemodule

How to use nanoid module on NodeJS?


I know that maybe this question is very silly, but I can't make nanoid to work on my NodeJS app.

I already read the docs.

This is my app.js configuration:

var nanoid = require("nanoid");
var ID = nanoid();

And I get the error message:

TypeError: nanoid is not a function
  at Object.<anonymous> (myapp.js directory)

Maybe I need to import the function inside nanoid but I dont know how to do it. Help would be appreciate. Thanks.


Solution

  • nanoid is a function inside the module try this

    var { nanoid } = require("nanoid");
    var ID = nanoid();