Ask coding questions

← Back to all posts
How to use a JS package in my replit
h
BeezerButt

hi

Sorry for this newbie questions.
I have successfully installed the "node-fetch" package.
I can see it in the left panel.

When I try to import fetch from the package to use for some example code, I fail to get it.

Its v3 of node-fetch so import is the only way.
I have tried 2 "flavours" of import...the latest is this one I saw on a post:

Voters
BeezerButt
Comments
hotnewtop
JacobBirch

Try this for your code:

JacobBirch

@CoderGautamYT This is what you tried explaining right?

CoderGautamYT

yup lol.. im bad at explaining things- @JacobBirch

BeezerButt

thanks for your reply @JacobBirch; i just tried the first line, and it is a quirk of v3 of node-fetch that it cannot work with require. It needs an import statement.
Is there an import equivalent?

CoderGautamYT

Try this at line 1:
const {fetch} = require('node-fetch')
This should work. i hope-

SixBeeps

@CoderGautamYT fetch() is async, what are you on about?

CoderGautamYT

i meant like in the code example you put await for your fetch which wouldnt work, nvm... @SixBeeps