
Node.js
玄冬Wong
别把自己当回事儿,我还是一只菜鸟……
展开
-
[io.js]CMD执行js脚本来实现文本文件拷贝
windows为例,下载安装文件直接安装完成,无需其他配置。官网:https://iojs.org 写一个拷贝文件的脚本,功能是:将src文件中的内容拷贝覆盖到dst文件中。文件名为test.js: var fs = require('fs');var dst = process.argv[3];var src = process.argv[2];fs.wr...原创 2016-01-26 16:17:02 · 390 阅读 · 0 评论 -
用nodejs抓取并存储网页内容
原文:前端乱炖 http://www.html-js.com/article/2558说明:原文中的API可能比较旧,最新版的superagent会有执行错误,在原文基础上代码修改了一些目标获取http://segmentfault.com/blogs/recommend?page=3页面的文章列表postList根据postList,逐个获取具体的文章页面...原创 2016-01-29 15:40:14 · 973 阅读 · 0 评论 -
[nodejs]filestream读写本地文件
原文:http://qianduanblog.com/post/nodejs-learning-4-filestream-read-write-local-file.html1、filestream API读文件:fs.readFile(异步)写文件:fs.writeFile(异步)追加内容:fs.appendFile(异步)核心例子为:// 引用 fs(fil...原创 2016-01-29 19:51:51 · 1962 阅读 · 0 评论 -
[nodejs]异步sleep和同步sleep(Asynchronous/Synchronous )
同步睡眠(Synchronous Sleep)方式1: setTimeout(function () { clearInterval(i); console.log('end');}, 100000);var i = setInterval(function () { console.log('ping');}, 1000); 方式2...原创 2016-01-29 21:03:42 · 1931 阅读 · 0 评论 -
[nodejs]按行读取文本文件
原文:https://segmentfault.com/a/1190000000740718 var stream = require('stream')var liner = new stream.Transform( { objectMode: true } )liner._transform = function (chunk, encoding, done) { ...原创 2016-01-29 21:39:24 · 2863 阅读 · 0 评论 -
[nodejs]异步读取并缓存多个文件
原文:http://stackoverflow.com/questions/9618142/asynchronously-reading-and-caching-multiple-files-in-nodejs When your callback to readFile executes, the for loop will already have finished. So i w...原创 2016-01-29 22:12:31 · 651 阅读 · 0 评论 -
[nodejs]字符串分割split
参考:http://stackoverflow.com/questions/21537543/how-to-split-a-string-by-node-js var arr = str.toString().split(","); 检测变量是否为字符串string:var arr;if (typeof str[0] == 'string') { arr =...原创 2016-01-30 00:22:00 · 16125 阅读 · 1 评论 -
[nodejs]hashmap的forEach()内调用外部变量的问题
在外部定义了两个HashMap:var HashMap = require('hashmap');var map1 = new HashMap();var map2 = new HashMap(); 当在其中一个map的forEach()函数内调用另外一个map的函数时,取不到正确的值:map1.forEach(function(value, key) { con...原创 2016-01-30 00:28:27 · 2797 阅读 · 0 评论 -
此博客永久停止更新,我的独立博客:dawnarc.com
告知:此博客永久停止更新,以后的文章只会更新到我的独立博客:https://dawnarc.com(2016-05-26夜晚·记)===============================================介绍两个静态页面博客框架:hexo和hugoHexo源码:https://github.com/hexojs/hexo官网:http...原创 2016-03-31 00:22:26 · 321 阅读 · 0 评论