require

node 转二进制 图片

核能气质少年 提交于 2019-11-29 19:41:09
'use strict'; const Service = require('egg').Service; const fs = require('fs'); const path = require('path'); const sendToWormhole = require('stream-wormhole'); class UploadService extends Service { async index() { const ctx = this.ctx; const stream = await ctx.getFileStream(); const fileName = stream.filename; let target = path.join(this.config.baseDir, `app/public/comfiles/${stream.filename}`); const result = await new Promise((resolve, reject) => { const remoteFileStream = fs.createWriteStream(target); stream.pipe(remoteFileStream); let errFlag; remoteFileStream.on('error', err => { errFlag

export 和 module.export 的区别

旧巷老猫 提交于 2019-11-29 19:37:56
在浏览器端 js 里面,为了解决各模块变量冲突等问题,往往借助于 js 的闭包把左右模块相关的代码都包装在一个匿名函数里。而 Nodejs 编写模块相当的自由,开发者只需要关注 require,exports,module 等几个变量就足够,而为了保持模块的可读性,很推荐把不同功能的代码块都写成独立模块,减少各模块耦合。 在 node 的 js 模块里可以直接调用 exports 和 module 两个“全局”变量,但是 exports 是 module.exports 的一个引用。 //plus.js function plus(a,b){ return a+b; } // 这样导出的 plus 是作为 exports 的一个方法被导出的 exports.plus = plus; // main.js var Plus = require('plus'); console.log(Plus.plus(1,2)); // 左边的 Plus 是 require 过来的模块名,右边的是它的 plus 方法。 在 node 编译的过程中,会把 js 模块封装成如下形式: // require 是对 Node.js 实现查找模块的 Module._load 实例的引用 // __finename 和 __dirname 是 Node.js 在查找该模块后找到的模块名称和模块绝对路径

深入理解node.js的module.export 和 export方法的区别

走远了吗. 提交于 2019-11-29 19:37:29
你肯定非常熟悉nodejs模块中的 exports 对象,你可以用它创建你的模块。例如:(假设这是rocker.js文件) exports.name = function() { console.log('My name is Lemmy Kilmister'); }; 在另一个文件中你这样引用 var rocker = require('./rocker.js'); rocker.name(); // 'My name is Lemmy Kilmister' 那到底 Module.exports 是什么呢?它是否合法呢? 其实, Module.exports 才是真正的接口, exports 只不过是它的一个辅助工具。 最终返回给调用的是 Module.exports 而不是 exports。 所有的 exports 收集到的属性和方法,都赋值给了 Module.exports 。当然,这有个前提,就是 Module.exports 本身不具备任何属性和方法 。如果, Module.exports 已经具备一些属性和方法,那么exports收集来的信息将被忽略。 修改rocker.js如下: module.exports = 'ROCK IT!'; exports.name = function() { console.log('My name is Lemmy

Require multiple files

不羁的心 提交于 2019-11-29 19:16:59
问题 I am building a PHP application that uses a select menu to build email templates. The templates are broken into reusable parts (each is a separate html file). Is there an easy way to require multiple files with one expression? (my PHP is really rusty...) Essentially I want to do something like: function require_multi() { require_once($File1); require_once($File2); require_once($File3); require_once($File4); } 回答1: Well, you could turn it into a function: function require_multi($files) {

Node.js “require” function and parameters

时光怂恿深爱的人放手 提交于 2019-11-29 19:15:27
When I do: lib = require('lib.js')(app) is app actually geting passed in? in lib.js: exports = module.exports = function(app){} Seems like no, since when I try to do more than just (app) and instead do: lib = require('lib.js')(app, param2) And: exports = module.exports = function(app, param2){} I don't get params2 . I've tried to debug by doing: params = {} params.app = app params.param2 = "test" lib = require("lib.js")(params) but in lib.js when I try to JSON.stringify I get this error: "DEBUG: TypeError: Converting circular structure to JSON" Raynos When you call lib = require("lib.js")

odoo12学习之javascript

丶灬走出姿态 提交于 2019-11-29 17:40:56
本文来源: https://www.jianshu.com/p/1a47fac01077 Odoo12 Javascript 参考指南 本文介绍了odoo javascript框架。从代码行的角度来看,这个框架不是一个大的应用程序,但它是非常通用的,因为它基本上是一个将声明性接口描述转换为活动应用程序的机器,能够与数据库中的每个模型和记录交互。甚至可以使用Web客户端修改Web客户端的接口。 概览 这个Javascript框架主要设计用于三个地方使用: web客户端:这是一个私有的web应用,可以在其中查看和编辑业务数据。这是一个单页应用程序(永远不会重新加载该页,只在需要时从服务器提取新数据)。 网站:这是Odoo的公共部分。它允许身份不明的用户作为客户端浏览某些内容、购物或执行许多操作。这是一个经典的网站:各种各样的带有控制器的路由和共同协作的Javascript代码。 POS:这是销售点的接口。它是一个特定的但也应用程序。 Web客户端 单页应用 简而言之,webclient实例是整个用户界面的根组件。它的职责是协调所有的子组件,并提供服务,如RPC、本地存储等等。 在运行时,Web客户端是单页应用程序。每次用户执行操作时,它不需要从服务器请求整页。相反,它只请求它所需要的,然后替换/更新视图。此外,它还管理URL:它与Web客户机状态保持同步。 这意味着

Why does require('underscore') return undefined when executed at the node.js REPL?

ε祈祈猫儿з 提交于 2019-11-29 17:10:44
问题 When I run node in my console and type var _ = require('underscore'); , _ ends up undefined. If I put the same code in a file and execute it, the underscore library gets included as expected. $ node > var _ = require('underscore'); > console.log(_) undefined // underscore library does not load > var async = require('async'); undefined > console.log(async) // async library does { noConflict: [Function], nextTick: [Function], forEach: [Function], ... > But the same code in a .js file executed

VUE json-server 模拟后台数据

删除回忆录丶 提交于 2019-11-29 16:37:25
0、先建一个json文件:data.json 放在跟目录下 1、使用json-server这个工具,可以虚构出后端接口对应的数据,然后在项目里发送特定的请求,就可以发请求拿到模拟的数据,首先npm安装   npm install json-server --save 2、在build/webpack.dev.conf.js中进行配置 'use strict' const utils = require('./utils') const webpack = require('webpack') const config = require('../config') const merge = require('webpack-merge') const path = require('path') const baseWebpackConfig = require('./webpack.base.conf') const CopyWebpackPlugin = require('copy-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin') const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') const

Backbone and Require how to add Qunit

坚强是说给别人听的谎言 提交于 2019-11-29 15:41:43
问题 I'm using Backbone and Require.js. Everything works great but, I would like to add some unit tests to my application. I decided use Qunit.js. In my main.js file I create new object EventsView : require.config({ paths: { jquery: 'libs/jquery', underscore: 'libs/underscore', backbone: 'libs/backbone', qunit: 'test/libs/qunit-1.10.0 } }); require(['view/eventsView', 'test/eventsView_test', 'test/eventView_test' ], function(EventsView){ var events = new EventsView; //here I create first object my

构建工具-Gulp 相关知识

▼魔方 西西 提交于 2019-11-29 12:36:29
layout: layout title: 『构建工具-Gulp』相关内容整理 date: 2017-04-26 22:15:46 tags: Gulp categories: Tools --- Gulp- 简介 Automate and enhance your workflow | 用自动化构建工具增强你的工作流程 Gulp 是什么? gulp是前端开发过程中一种基于流的代码构建工具,是自动化项目的构建利器;它不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成; 使用它,不仅可以很愉快的编写代码,而且大大提高我们的工作效率。 gulp是基于Nodejs的自动任务运行器,它能自动化地完成 javascript、coffee、sass、less、html/image、css 等文件的测试、检查、合并、压缩、格式化、浏览器自动刷新、部署文件生成,并监听文件在改动后重复指定的这些步骤。在实现上,她借鉴了Unix操作系统的管道(pipe)思想,前一级的输出,直接变成后一级的输入,使得在操作上非常简单。通过本文,我们将学习如何使用Gulp来改变开发流程,从而使开发更加快速高效。 gulp 和 grunt 非常类似,但相比于 grunt 的频繁 IO 操作,gulp 的流操作,能更快地更便捷地完成构建工作。 Gulp的核心概念? 流