require

迁移到 Express 4.x

你说的曾经没有我的故事 提交于 2019-12-05 11:01:46
迁移到 Express 4.x 概览 从 Express 3 到Express 4 是一个巨大的变化,这意味着现存的 Express 3 应用在不更新依赖的情况下将不能工作。 这篇文章涵盖一下内容: Express 4 中的变化 一个从 Express 3 迁移到 Express 4 的示例 升级到 Express 4 的应用生成器 Express 4 中的变化 主要的变化如下: Express 的核心和中间件系统:对 Connect 和内建中间件的依赖被移除了。所以你必须自己添加中间件。 路由系统 其它 参见: 4.X 中的新特性 从 3.X 迁移到 4.X Express 的核心和中间件系统 Express 4 不再依赖 Connect,并且从核心中移除了所有内建的中间件,除了 express.static 之外。这意味着 Express 现在是一个不依赖路由和中间件的 Web 框架。这样 Express 的版本化和发布就不再受到中间件的影响。 随着内建的中间件被移除,你必须显式添加所有依赖的中间件来运行你的应用,简单来说需要以下步骤: 安装模块:npm install –save 模块名称 在你的应用中,使用这个模块: require( 模块名称 ) 基于模块的文档来使用模块 下表列出了 Express 3 中对应 Express 4 中的模块 Express 3

cordova-plugin-crypt-file - requireCordovaModule error

血红的双手。 提交于 2019-12-05 10:30:06
I just upgrade Cordova to version 9. It cased plugin cordova-plugin-crypt-file to stop working - when I build the application, I get error Using "requireCordovaModule" to load non-cordova module "path" is not supported. Instead, add this module to your dependencies and use regular "require" to load it. It looks like the issue is with file hooks/after_prepare.js. The code is var path = context.requireCordovaModule('path'), fs = context.requireCordovaModule('fs'), crypto = context.requireCordovaModule('crypto'), Q = context.requireCordovaModule('q'), cordova_util = context.requireCordovaModule(

passing parameters to php include/require construct

╄→尐↘猪︶ㄣ 提交于 2019-12-05 10:02:47
问题 I've read quite a few posts that are very similar to the question I'm about to ask, but I just wanted to be sure that there wasn't a more sophisticated way to do this. Any feedback is greatly appreciated. I want to create a mechanism to check whether or not a logged-in user has access to the php script that is currently being called . If so, the script will continue on; if not, the script just fails out using something like die('you have no access') . I came up with two ways of accomplishing

How to create include files in Lua language?

十年热恋 提交于 2019-12-05 09:19:05
问题 I want to create a header file in Lua (header.lua), then execute the require function to load it. How do I execute require to a file that I have created? 回答1: require "header" See the require entry in the Lua Reference manual. The file "header.lua" must be somewhere in Lua's search path. You can see (and modify) the path at package.path See the package.path entry in the the Lua Reference Manual This wiki page describes ways of creating modules to load with require . 回答2: You have loadfile and

Web scraping with CasperJS returns strange error that isn't documented

做~自己de王妃 提交于 2019-12-05 07:14:28
I wrote an web scraping script with CasperJS and it works perfectly on Mac OS 10.10.4 with CasperJS version 1.1.0-beta3 and PhantomJS version 1.9.8, but when I put the same script on one of my servers which is Ubuntu 14.04 (running inside Docker container) with the same environment (CasperJS and PhantomJS all the same versions) it suddenly just outputs this: I'm `fs` modules Which is pretty strange. One of my suggestion is that in this script I am also trying to require some other scripts with require like that: var parsingStrategy = require(strategiesPath + strategyName); and the path to

nodejs入门之模块

我与影子孤独终老i 提交于 2019-12-05 05:10:23
nodejs模块语法与开闭原则 nodejs模块的底层实现 一、nodejs模块语法与开闭原则 关于nodejs模块我在之前的两篇博客中都有涉及,但都没有对nodejs模块的底层做做任何探讨,但是为了使相关内容跟方便查看比对理解,这里还是先引入一下之前两篇博客的连接: js模块化入门与commonjs解析与应用 ES6入门十二:Module(模块化) 1.1 exports、module.exports、require()实现模块导出导入: 1 //示例一:导出原始值数据 2 //a.js--用于导出数据 3 let a = 123; 4 module.exports.a=a; 5 //inde.js--用于导入a模块的数据 6 let aModule = require('./a.js'); 7 console.log(aModule.a); //123 8 9 //示例二:导出引用值数据 10 //a.js--同上 11 function foo(val){ 12 console.log(val); 13 } 14 module.exports.foo = foo; 15 //index.js--同上 16 let aModule = require('./a.js'); 17 let str = "this is 'index' module" 18 aModule.foo

node.js框架 express

别等时光非礼了梦想. 提交于 2019-12-05 04:34:39
express是在node.js的基础上,拓展出的一个简洁实用的框架结构,运用这个东西,我们可以更方便的处理很多的事情。只要上手了,那就是个贝多芬! 一般安装express有几种方法。 第一,使用npm安装,cmd中输入npm install express -g,这个-g是全局安装,也就是安装在被你用"config set global"设置的文件夹里,需要注意的是,安装完了以后,需要改变环境变量以及其路径来指向你的安装目录。 第二,复制粘贴。(……废话!)不过这样的存在安全性问题,因为在复制粘贴的过程中,可能会有数据丢失之类的情况出现。 最后,值得注意的是,一旦在你的nodejs中存在了一个文件夹里面放置了express框架,而且他被你引用过,那么无论你怎么挽救也是无用的……要么把它删除,要么把它覆盖。 express() 创建一个express应用程序 相当于new一个对象,但是还能少写三个字母,将express存入变量app中,从此app翻身做主人! 1 2 3 4 5 6 7 var express = require( 'express' ); var app = express(); app.get( '/' , function (req, res){ res.send( 'hello world' ); }); app.listen(3000); app.set

web 响应 html

怎甘沉沦 提交于 2019-12-05 04:26:38
var http = require("http"); var fs = require("fs"); var server = http.createServer(function (request, response) { response.writeHead(200, { "Content-type": "text/html" }) var stream = fs.createReadStream(__dirname + "/index.html", "utf-8"); stream.pipe(response); }); server.listen(4000, "127.0.0.1"); server.on("error", function (e) { if (e.code == "EADDRINUSE") { console.log("in error") setTimeout(function () { server.close(); server.listen(4000, "127.0.0.1") }, 1000); } }) console.log("server has started") 来源: https://www.cnblogs.com/lbx6935/p/11905715.html

override setTimeout in require.js

浪尽此生 提交于 2019-12-05 04:18:47
we are using require.js in our project and we need to override the setTimeout in line 705 , this is the code which we need to ignore/omit somehow this setTimeout at all(I mean run over it) ,the problem that if I change it in the open source code explicit when I change version the code will be lost,How should I override this setTimout from outside only for the require.js file and keep it as long as I use this lib, is it possible to do it in elegant way in JS globally ? https://github.com/jrburke/requirejs/blob/master/require.js This is line 705 //If still waiting on loads, and the waiting load

Writing Files In Nodejs? Here Is What You Need To Know.

只谈情不闲聊 提交于 2019-12-05 04:18:07
NodeJs file system module will allow us to do file operations create, read, write, update, delete, rename. In this blog, we will use the fs module to perform file operations. In the fs module, every method has asynchronous as well as synchronous forms. Asynchronous methods take the first parameter of the callback function as error and the last parameter as the completion function callback. It’s better to go with the asynchronous method instead of the synchronous method. Now let’s move on to Nodejs file examples Step 1: Create a directory for our application. $ mkdir nodeFileOperations $ cd