Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 775
Tomi Melone Avatar asked Apr 22 '20 20:04

Tomi Melone


People also ask

What is NanoID in node JS?

A tiny, secure, URL-friendly, unique string ID generator for JavaScript. “An amazing level of senseless perfectionism, which is simply impossible not to respect.”

What does NanoID do?

Introducing Nano ID It is a tiny, secure, URL-friendly, unique string ID generator. Nano ID has smaller size as compared to UUID. This size reduction impacts a lot. Making use of NanoID is easier for transferring information and storage space.

Is NanoID unique?

The above benchmarks show the performance of NanoID compared to other major id generators. It can generate over 2.2 million unique IDs per second with its default alphabet and over 1.8 million unique IDs per second when using the custom alphabet.


1 Answers

nanoid is a function inside the module try this

var { nanoid } = require("nanoid");
var ID = nanoid();
like image 119
Neriya Bar-lev Avatar answered Oct 22 '22 18:10

Neriya Bar-lev