Ask coding questions

← Back to all posts
How can I use multiple Files in a NodeJS Repl?
somecodingguy

I am a creating a chat app and I want to be able to use multiple server-side files. I have created a demo Repl as linked. I tried using const file = require('indexOne.js'); but it thinks I want to install. How can I do this?

Thank you

Voters
somecodingguy
Comments
hotnewtop
somecodingguy

but how would I access a function from the other file?

Coder100

use module.exports to export a variable, function, or object. @somecodingguy

somecodingguy

@Coder100 Yes this works but how would I have multiple functions? Sorry

Coder100

using object destructoring, if your file was

then you can import like

@somecodingguy

somecodingguy

@Coder100 so how would I do it with functions? Sorry

Coder100

same thing
functions are variables??? @somecodingguy

somecodingguy

@Coder100 like that?

Coder100

no, here is the correct example:

you only do destructuring for objects.
@somecodingguy

somecodingguy

@Coder100 yes I realized that but i gues i cant use multiple functions.

EpicGamer007

put ./ in the string for the require.