Questions tagged [require]

In interpreted languages like Lua, PHP and Ruby, "require" is a statement that tells the interpreter to include a certain source-file at that position where the "require" statement has been placed.

Require in PHP

In PHP there exist the statements include() and require() to include another file with PHP-code into your document.
The difference to include is, that require will throw an error if the file is not available.

A variant of require() is require_once(). This includes a file only, if it hasn't already been included before.

require('/path/to/script.php');

Require in Ruby

In Ruby, the require method does what include does in most other programming languages: It will include and run another file.

It also tracks what you've required in the past and won't require the same file twice. To run another file without this added functionality, you can use the load method.

require '/path/to/script.rb'

The include and require methods do very different things. Please check the source for further information on include.

Source: http://ruby.about.com/b/2008/10/23/a-quick-peek-at-ruby-include-vs-require.htm

Require in JavaScript

JavaScript has no native support for the require statement. However, there exist various implementations that try to mimic the behaviour of other programming languages.

These implementations are not fixed to use the word "require" for their loading routines, but may use other statements.

Some of them are:

const someModule = require('/path/to/module.js');
    require(["moduleA", "moduleB"], function(A, B) {
       // do something with moduleA ...
       A.doSomething();
       // do something with moduleB ...
       B.doSomething();
    });
    head.js("/path/to/script.js");
    $LAB.script("/path/to/script.js");

Require in Lua

The require statement of Lua searches for a module with the given name automatically extended by a previously defined path pattern.

The path patterns are rules that specify how to construct a path name using the parameter given to require. After path construction, require will check if one of the constructed paths is valid in order to load this path.

The pattern usually includes an expression, which extends the given name by '.lua', Lua caches already loaded modules, so they won't be loaded twice.

    require "module"
3188 questions
1
vote
2 answers

PHP file does exist but can't require_once()

So recently I decided to move my php code that was at the top of every page, and exactly the same to it's own php file. First thing I did before trying a require_once() on it was to make sure php could read the file so I did
MrRevolutionz
  • 11
  • 1
  • 2
1
vote
1 answer

Node JS is says method isn't there when it clearly is

Alright, so I've created a test project to show off this error. The error being that Node JS can't find my getStr function in my Another object. This is the code: test.js var Another = require('./another.js'); var Other = require('./other.js'); var…
CyanPrime
  • 5,096
  • 12
  • 58
  • 79
1
vote
1 answer

'require uri' in not working in Rails 4 app

Trying to "require 'uri'" in a utility class and it doesn't seem to be loading. Keep getting the error: NoMethodError at / undefined method `query' for "https://api.twitter.com/1.1/search/tweets.json?q=%40twitterapi":String Whereas the .query…
Kyle Chadha
  • 3,741
  • 2
  • 33
  • 42
1
vote
3 answers

Php - check if an include or block of code has an error

How would I go about checking if and include or a require has an error in it. For example, and include would try to be included, if that page has an error the page isn't included and a message is throw? Cheers.
CafeHey
  • 5,699
  • 19
  • 82
  • 145
1
vote
2 answers

Nodejs delay return for "require"

My setup is as follows: Nodejs Server server.js requires utils.js utils.js loads data from mongodb into memory and exports it server.js uses a variable that utils.js exports The issue that I am worried about is the fact that the mongodb call is…
Franz Payer
  • 4,069
  • 15
  • 53
  • 77
1
vote
1 answer

require.js loaded modules are null for bootstrap and parse

I am trying to load Parse JS (parse.com) and Bootstrap JS using RequireJS. I can't get it to work with these libraries, but other libraries seem to work fine (e.g. backbone.js). I have made sure to include this in my index.html file:
1
vote
1 answer

Ruby require - execute multiple times

A general question about require in Ruby. My understanding of Ruby's require is that the file specified is only loaded once but can be executed multiple times. Is this correct? I have a set of Rspec tests in different files which all require the…
chibi03
  • 121
  • 1
  • 9
1
vote
1 answer

manually require 'Bootsy' in assets pipeline Rails 4 application.css vs application.css.scss

I'm using a WYSIWYG called Bootsy. docs here: http://volmer.github.io/bootsy/ I did this command and got: $ rails generate bootsy:install route mount Bootsy::Engine => '/bootsy', as: 'bootsy' create config/locales/bootsy.en.yml insert …
user3138341
  • 219
  • 2
  • 3
  • 12
1
vote
1 answer

AngularJS directive require parent directive doesn't work

I want to make a categories tree with checkboxs (which is a recusive list) directive. I did a directive called categoriesTreeContainer that containes all the list of categories and I did another directive called categoryItem that containes the…
Sn0opr
  • 1,016
  • 2
  • 12
  • 38
1
vote
1 answer

RequireJS require() cannot resolve file names at the same subdirectory level

I've got a directory structure like so: app/ ├ js/ │ ├ gui/ │ │ ├ main.js │ │ └ santa.js │ └ app.js └ index.html <- includes requirejs and starts js/app.js app.js: baseUrl: 'js' // Pseudo-code for requirejs.config() of…
Redsandro
  • 11,060
  • 13
  • 76
  • 106
1
vote
3 answers

how to declare all your includes in one file that will be loaded in all project in PHP

i'm working on a project but, i'm sick of loading all the libraries in every single page my project directories are something like this |---x (( PHP PAGES )) |--- x1.php (( PHP FILE )) |--- x2.php (( PHP FILE )) |---y (( PHP PAGES )) |---…
trrrrrrm
  • 11,362
  • 25
  • 85
  • 130
1
vote
1 answer

using Raphael with require js and eve js

I am familiar with Raphael.js and I am using it in my web application. But,What is the purpose of converting the Raphael java script file into modules published in the this article https://github.com/vraa/raphael-require The new module files are--->…
subramanya
  • 91
  • 1
  • 11
1
vote
0 answers

Mongoose referencing models in other models

I am working on an express/node app, using mongodb and mongoose to model users, players, teams, etc. Between these models I am using references with ObjectIDs, so between players and teams there is a connector model RosterSpot which holds a team_id…
1
vote
0 answers

Implementing simple jQuery plugins with AngularJS (and RequireJS)

I'm currently using Angular and Require in a project for the first time. At the moment it seems like it's very hard to do the things that should be simple when using Angular. I'm currently trying to put a click event using jQuery for a simple tabbed…
30secondstosam
  • 4,476
  • 4
  • 28
  • 33
1
vote
2 answers

Is it possible require file content "as is" in TypeScript?

Typescript defines comment with xml tag to source local files to current file. But that tag could be placed only in file header before declaring any structures such us other modules. So, // File1.ts - correct ///
Pavel Patrin
  • 1,630
  • 1
  • 19
  • 33
1 2 3
99
100