require

Using Node.js modules in HTML

别来无恙 提交于 2019-12-01 04:25:41
I have the following Node.js project (which is a Minimal Working Example of my problem): module1.js : module.exports = function() { return "this is module1!"; }; module2.js : var module1 = require('./module1'); module.exports = function() { return module1()+" and this is module2!"; }; server.js : var module2 = require('./module2'); console.log(module2()); // prints: "this is module1! and this is module2!" Now I want to create a client.html file that will also use module2.js. Here is what I tried (and failed): naive version : <script src='module2.js'></script> <script>alert(module2());</script>

Subfolders in lib

喜你入骨 提交于 2019-12-01 03:48:37
问题 I have a module called user_searches. It performs some searches that aren't core to the user model, thus, why I'm putting the responsibility somewhere else. I want to organize all my models like this that perform non-core user functions in a lib subfolder called user. Right now to include the module's methods in the User model I have to put... require 'user/user_searches' class User < ActiveRecord::Base include UserSearches end ...I don't need the require if the file is directly in the lib

Require nodejs “child_process” with TypeScript, SystemJS and Electron

南笙酒味 提交于 2019-12-01 03:36:54
I'm working on a simple nodejs electron (formerly known as atom shell) project. I'm writing it using angular 2, using the project the same project setup as they recommend in the documentation for typescript: tsc: { "compilerOptions": { "target": "es5", "module": "system", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false }, "exclude": [ "node_modules", "typings/main", "typings/main.d.ts" ] } I need to run a command, I found out that I can do it with node "child_process". I couldn't find

Require ruby file without .rb extension?

跟風遠走 提交于 2019-12-01 03:07:10
I have a ruby file that does not have a .rb extension, and is instead identified as ruby code with a shebang at the beginning of the file: #!/usr/bin/env ruby . I want to require the code in this file in another ruby file, but it seems to be having a problem because require automatically appends the .rb extension to the files it looks for. Is there any way to suppress this behavior and make require only look for the file as the name is given? Use load instead: load 'file-name' We have scripts the users are allowed to call, which are accessed using symlinks. The symlinks exist in our /usr/local

Using Node.js modules in HTML

天涯浪子 提交于 2019-12-01 03:06:13
问题 I have the following Node.js project (which is a Minimal Working Example of my problem): module1.js : module.exports = function() { return "this is module1!"; }; module2.js : var module1 = require('./module1'); module.exports = function() { return module1()+" and this is module2!"; }; server.js : var module2 = require('./module2'); console.log(module2()); // prints: "this is module1! and this is module2!" Now I want to create a client.html file that will also use module2.js. Here is what I

Resolve “Uncaught ReferenceError: require is not defined” error in Node.js

匆匆过客 提交于 2019-12-01 02:49:41
问题 I am trying to set up a basic contact form using SengGrid and I keep getting a "Uncaught ReferenceError: require is not defined" error. I have this code in a script tag in the head of the html page. var sendgrid = require('sendgrid')(username,pass); I have looked at requirejs, but I am not sure why I am getting this error. Could someone explain to me how I can resolve this issue? 回答1: require() is not built into the browser. So when you say that "I have this code in a script tag in the head

php 中使用include、require、include_once、require_once的区别

倖福魔咒の 提交于 2019-12-01 02:42:51
在PHP中,我们经常会通过include、require、include_once、require_once来引用文件,都可以达到引用文件的目的,但他们之间又有哪些区别呢,接一下我们详细的介绍一下 include:使用include引用外部文件时,只有代码执行到include代码段时,调用的外部文件才会被引用并读取,当引用的文件发生错误时,系统只会给出个警告错误,而整个php文件会继续执行。 require:在php文件被执行之前,php解析器会用被引用的文件的全部内容替换require语句,然后与require语句之外的其他语句组成个新的php文件,最好后按新的php文件执行程序代码。 include和require的区别 使用require语句来调用文件时,如果调用的文件没有找到,require语句会输出错误信息,并且立即终止脚本处理。儿include语句在没有找到文件时则会输出警告,不会终止脚本的处理。 使用require语句调用文件时,只要程序一执行,就会立刻调用外部文件。而通过include语句调用外部文件时,只有程序执行到该代码段时,才会调用外部文件。 include_once:使用include_once会在导入文件前先检测该文件是否在该页面的其他部分被应用过,如果有,则不会重复引用该文件,程序只能引用一次。(要导入的文件中存在一些自定义函数

Including a whole directory in PHP or Wildcard for use in PHP Include?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 02:09:45
问题 I have a command interpreter in php. It lives inside the commands directory and needs access to every command in the command file. Currently I call require once on each command. require_once('CommandA.php'); require_once('CommandB.php'); require_once('CommandC.php'); class Interpreter { // Interprets input and calls the required commands. } Is there someway to include all of these commands with a single require_once? I have a similar problem many other places in my code (with factories,

How do I rescue from a `require': no such file to load in ruby?

别等时光非礼了梦想. 提交于 2019-12-01 02:03:14
I am trying to rescue from a ``require': no such file to load in ruby` in order to hint the user at specifying the -I flag in case he has forgotten to do so. Basically the code looks like: begin require 'someFile.rb' rescue puts "someFile.rb was not found, have you" puts "forgotten to specify the -I flag?" exit end I have expected the rescue part to take over execution in case someFile.rb was not found, but my assumption was wrong. rescue without arguments rescues only StandardError s. The LoadError (that is raised by a file not found) is not a StandardError but a ScriptError (see http://blog

Node.js require vs React.js import

久未见 提交于 2019-12-01 01:26:21
I know that in Node.js, when you require some file with variables or functions, from the second time it loaded from the memory. This concept is the same in import in React.js? Can i load multiply variables or functions using import, and it will load from the memory in the second time? React is UI library. It isn't related to import keyword. Any available JavaScript features can be used together with React, including import - or require , if it's available. The question is about ES vs CommonJS modules. The former are universal, the latter are primarily used in Node but also suppored by Webpack