mardi 10 octobre 2017

Node.js External function calling

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

Aucun commentaire:

Enregistrer un commentaire