Ask coding questions

← Back to all posts
Why wont Node let me import things
h
AlmightyDeaks (5)

Hi, I am trying to import a module to create a UUID but it just gives me an error. I am following this tutorial: https://www.devextent.com/npm-generate-unique-id/
i am fairly new to JavaScript but have never used node.js
if you know how to help please do

Answered by OldWizard209 (1544) [earned 5 cycles]
View Answer
Comments
hotnewtop
OldWizard209 (1544)

Did you initiate npm(Node Package Manager). This will allow you to use packages. First you have to initialize npm. Write this in the shell.
npm init

Then install any package you want with in this case UUID:
npm install uuid

Then require it in your code:

const { v4: uuidv4 } = require("uuid");