require

如果不用 Node.js 写业务

给你一囗甜甜゛ 提交于 2019-12-03 04:11:17
本文转载于: 猿2048 网站➸ https://www.mk2048.com/blog/blog.php?id=h0jbbh1cbb 本站使用「署名 4.0 国际 (CC BY 4.0)」许可协议,欢迎转载、或重新修改使用,但需要注明来源。 署名 4.0 国际 (CC BY 4.0) 本文作者: 苏洋 创建时间: 2018年08月31日 统计字数: 4273字 阅读时间: 9分钟阅读 本文链接: https://soulteary.com/2018/08/31/play-with-node.html 如果不用 Node.js 写业务 最近整理博客,发现很久没有介绍语言相关的小用法了,正巧休息的时候把代码仓库归置了一遍,用几个简短的例子,聊聊 Node.js 除了写业务脚本、做构建运行时,它还能做些什么有趣的事情吧。 持续集成中的粘合剂 在做持续集成中,偶尔会遇到需要解析 API 结果,或者读取文件,获取文件指定数据的需求,当使用常规的 shell 难以完成需求的时候,相比较 Python 来说使用 Node 做为粘合剂来获取数据不失为一个好的方案,因为写出的代码将会更简单明了。 示例 比如你希望获取到某些 API 中的特殊字段,然后再次进行参数拼装,请求其他的 API ,完成某种程度的完全自动化操作。 使用 Node.js 的 fs.readFileSync 方法读取 /dev

Angular2 5 minute install bug - require is not defined

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm doing the Angular2 5 minute quick start . About half way through the tutorial now, I have the following files setup correctly: index.html, app.component.ts app/boot.ts package.json tconfig.json Ran npm start and am getting this error: Uncaught ReferenceError: require is not defined(anonymous function) @ boot.js:1 angular2-polyfills.js:14 3 Uncaught TypeError: Cannot read property 'split' of undefinedreadMemberExpression @ system.src.js:1456(anonymous function) @ system.src.js: 3 224(anonymous function) @ system.src.js: 3 749complete @

Access RequireJS path configuration

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I notice in the documentation there is a way to pass custom configuration into a module : requirejs . config ({ baseUrl : './js' , paths : { jquery : 'libs/jquery-1.9.1' , jqueryui : 'libs/jquery-ui-1.9.2' }, config : { 'baz' : { color : 'blue' } } }); Which you can then access from the module: define ([ 'module' ], function ( module ) { var color = module . config (). color ; // 'blue' }); But is there also a way to access the top-level paths configuration, something like this? define ([ 'module' , 'require' ], function ( module ,

Xcode 9 throws errors involving 'require'

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When upgrading code to build under Xcode 9, I see compile errors in code using require and require_noerr : require(length > offsetof(struct blob, cert), outLabel); The first error is: error: implicit declaration of function 'require' is invalid in C99 I also get a lot of error: use of undeclared identifier 'outLabel' . This is in RRTransactionVerifier.m which is Apple code for dealing with receipt validation. How do I fix these errors? 回答1: require and require_noerr are macros that used to be defined in AssertMacros.h. As of Xcode 9 these

Passport local strategy and cURL

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I would like to test my node.js + express + passport.js test application (RESTful) with CURL. My code: var express = require ( 'express' ); var routes = require ( './routes' ); var http = require ( 'http' ); var path = require ( 'path' ); var passport = require ( 'passport' ); var LocalStrategy = require ( 'passport-local' ). Strategy ; // Define the strategy to be used by PassportJS passport . use ( new LocalStrategy ( function ( username , password , done ) { if ( username === "admin" && password === "admin" ) // stupid example

“unexpected token import” in Nodejs5 and babel?

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: In js file, i used import to instead of require import co from 'co' ; And tried to run it directly by nodejs since it said import is 'shipping features' and support without any runtime flag ( https://nodejs.org/en/docs/es6/ ), but i got an error import co from 'co' ; ^^^^^^ SyntaxError : Unexpected token import Then i tried to use babel npm install - g babel - core npm install - g babel - cli npm install babel - core //install to babel locally, is it necessary? and run by babel - node js . js still got same error, unexpected token

Node JS and Webpack Unexpected token <

匿名 (未验证) 提交于 2019-12-03 03:05:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've started studing Node JS . So here is my files. index.html Hello app.js var http = require("http"), path = require('path') fs = require("fs"), colors = require('colors'), port = 3000; var Server = http.createServer(function(request, response) { var filename = path.join(__dirname, 'index.html'); fs.readFile(filename, function(err, file) { if(err) { response.writeHead(500, {"Content-Type": "text/plain"}); response.write(err + "\n"); response.end(); return; } response.writeHead(200); response.write(file); response.end(); }); }); Server

Rails server does not start -> Could not find a JavaScript runtime [duplicate]

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: execJs: 'Could not find a JavaScript runtime' but execjs AND therubyracer are in Gemfile 20 answers I created a new rails app in folder 'issues' and when I wanted to 'ruby s' I got an error. Any help will be much appreciated [thiago@netbox issues]$ rails s /home/thiago/.rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from

rails and bootstrap: Uncaught ReferenceError: jQuery is not defined

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I created a simple webapp integrating bootstrap 3 in a rails 3.2.17 application, following this procedure found on stackoverflow, so without using a gem but manually copying the bootstrap files in the relevant app directories. Even if i have, in my gem file: gem 'jquery-rails' i can still see, inspecting my web page with chrome, the error: Uncaught ReferenceError: jQuery is not defined My page is a "normal" html page in public directory. Maybe it doesn't "inherit" all the assets stuff? The code is like this: <!DOCTYPE html> <html> <head>

require(&#039;babel/register&#039;) doesn&#039;t work

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have isomorphic app written in ES6 on client with Babel transpiler . I want my express server to have the same ES6 syntax as client code. Unfortunately require('babel/register') doesn't work.. server.js require('babel/register'); // doesn't work // require('babel-core/register); doesn't work.. const env = process.env.NODE_ENV || 'development'; const port = process.env.NODE_PORT || 1995; const http = require('http'); const express = require('express'); const address = require('network-address'); let app = express(); app.set('port', port);