require

How do I change the order in which Meteor loads Javascript files?

别等时光非礼了梦想. 提交于 2019-11-26 09:24:47
问题 When you make a project with the Meteor framework, it packages all the files together, but there doesn\'t seem to be a way to explicitly say \"I want this file to be loaded before that one\". Let\'s say, for example, I have 2 javascript files: foo.js and bar.js . The file bar.js is actually containing code depending one the one inside foo.js but Meteor is loading bar.js before foo.js , breaking the project. In node.js I would simply use require(\'./bar\') inside foo.js In the browser , I

node.js require all files in a folder?

拥有回忆 提交于 2019-11-26 08:50:36
问题 How do I require all files in a folder in node.js? need something like: files.forEach(function (v,k){ // require routes require(\'./routes/\'+v); }}; 回答1: When require is given the path of a folder, it'll look for an index.js file in that folder; if there is one, it uses that, and if there isn't, it fails. It would probably make most sense (if you have control over the folder) to create an index.js file and then assign all the "modules" and then simply require that. yourfile.js var routes =

What is the difference between require('mypackage.js') and require('mypackage')?

被刻印的时光 ゝ 提交于 2019-11-26 08:25:15
问题 Both these require statements appear to work the same way: var Mypackage = require(\'mypackage.js\'); var Mypackage require(\'mypackage\'); Is there a difference between them? 回答1: Here is the answer: Module.prototype.load = function(filename) { debug('load ' + JSON.stringify(filename) + ' for module ' + JSON.stringify(this.id)); assert(!this.loaded); this.filename = filename; this.paths = Module._nodeModulePaths(path.dirname(filename)); var extension = path.extname(filename) || '.js'; if (

Browserify with require('fs')

末鹿安然 提交于 2019-11-26 07:43:18
问题 I was trying to use browserify on a file that uses the fs object. When I browserify it, the call to require(\'fs\') doesn\'t get transformed and require returns {} . Is there any workaround for this? I\'ve seen some suggestions on stackoverlow and elsewhere, but none seem to be fully realized. I actually hoped to create a google web packaged app using browserify for a class I teach. Thanks in advance. 回答1: Which filesystem should the browser use then? The HTML5 filesystem is not really

Node-style require for in-browser javascript?

你。 提交于 2019-11-26 06:05:46
问题 Are there any libraries for in-browser javascript that provide the same flexibility/modularity/ease of use as Node\'s require ? To provide more detail: the reason require is so good is that it: Allows code to be dynamically loaded from other locations (which is stylistically better, in my opinion, than linking all your code in the HTML) It provides a consistent interface for building modules It is easy for modules to depend on other modules (so I could write, for instance, an API that

How to deal with cyclic dependencies in Node.js

安稳与你 提交于 2019-11-26 05:40:43
问题 I\'ve been working with nodejs lately and still getting to grips with the module system so apologies if this is an obvious question. I want code roughly like the following below: a.js (the main file run with node) var ClassB = require(\"./b\"); var ClassA = function() { this.thing = new ClassB(); this.property = 5; } var a = new ClassA(); module.exports = a; b.js var a = require(\"./a\"); var ClassB = function() { } ClassB.prototype.doSomethingLater() { util.log(a.property); } module.exports

webpack dynamic module loader by require

送分小仙女□ 提交于 2019-11-26 05:38:41
问题 OK, i have searched high and low but cannot reliably deterrmine if this is or is not possible with webpack. https://github.com/webpack/webpack/tree/master/examples/require.context Appears to indicate that one can pass a string to a function and it load a module... But my attempt is just not working: webpack.config.js \'use strict\'; let webpack = require(\'webpack\'), jsonLoader = require(\"json-loader\"), path = require(\"path\"), fs = require(\'fs\'), nodeModules = {}; fs.readdirSync(\'node

Load node.js module from string in memory

我与影子孤独终老i 提交于 2019-11-26 05:23:18
问题 How would I require() a file if I had the file\'s contents as a string in memory, without writing it out to disk? Here\'s an example: // Load the file as a string var strFileContents = fs.readFileSync( \"./myUnalteredModule.js\", \'utf8\' ); // Do some stuff to the files contents strFileContents[532] = \'6\'; // Load it as a node module (how would I do this?) var loadedModule = require( doMagic(strFileContents) ); 回答1: function requireFromString(src, filename) { var Module = module

nodejs知识点小整理

只愿长相守 提交于 2019-11-26 04:17:40
1. vs code 里面如何切换自定义终端? 2. 浏览器 vs node 异: node里面没有 BOM DOM node多了很多自带的api 同: 都是chrome v8 都支持js 都支持 ECMA Script 3. 需求: sum这个方法, 我想三个参数 , 计算三个参数值? Node.js 命令行有时候用起来不方便 解决: 我们使用文件 .js Node.js命令行退出 two times ctrl+c Node.js文件运行 node 文件名称(后缀可以不要) 键盘上下键可以前进和回退命令 自动监听(自动更新, 自动刷新)Node.js文件的更新和变化( 工具 nodemon supervisor) 使用淘宝镜像 工具安装 cnpm i nodemon -g (i==> install g ==> global) 推荐 cnpm i supervisor -g 使用: nodemon 文件名称 supervisor 文件名称 注意事项: 问题: supervisor 会出现死循环 ? 分析: 内容一致在改变 解决: vs code 开了自动保存 nvm 使用 安装: nvm install vsersion 举例: nvm install v10.8.0 || nvm install 10.8.0 || nvm install latest(最新版本) 切换Node

Best way to require all files from a directory in ruby?

泪湿孤枕 提交于 2019-11-26 04:03:15
问题 What\'s the best way to require all files from a directory in ruby ? 回答1: How about: Dir["/path/to/directory/*.rb"].each {|file| require file } 回答2: If it's a directory relative to the file that does the requiring (e.g. you want to load all files in the lib directory): Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file } Edit: Based on comments below, an updated version: Dir[File.join(__dir__, 'lib', '*.rb')].each { |file| require file } 回答3: Try the require_all gem: http:/