0

So I've been using NodeJS but I have a heavy background on C and C++, and I would like to know how would I "simulate" the header effect on NodeJS.

I have the following code

foo.js

 var Discord = require("discord.js");
    var request = require('request');
    var http = require('http');
    var express = require('express');
    var util = require('./dead.js');

util.beef()

then inside the other .js file

dead.js

exports.module = {
beef: function(){ request(something) }
}

I'm trying to make use of the request variable before declared inside foo.js, but it won't work because Node says it doesn't exist (so, ok it went out of scope)

  1. Do I have to require every file I want to use in dead.js?
  2. Would using require impact the performance too much?
  3. When is it preferable to have a long single js file rather than have multiple ones and require in each one

1 Answer 1

1

You need to require() every file every time you use it.

You cannot share variables directly across files, and this is a good thing (it prevents conflicts).

require() caches everything, so there are no performance concerns.

You should not put everything in a single giant JS file; that would be hard to maintain.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.