码迷,mamicode.com
首页 > 其他好文 > 详细

Node学习

时间:2014-12-16 16:30:29      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   ar   io   color   os   sp   

参见Node入门 做出node应用的第一个例子 图片上传浏览。

  bubuko.com,布布扣bubuko.com,布布扣

bubuko.com,布布扣

过程中遇到的问题:

1.npm安装formidable模块失败的解决办法

 借鉴:解决途径

直接去github下载formidable模块(地址:https://github.com/felixge/node-formidable

2.运行错误:fs.js:330 return binding.rename(pathModule._makeLong(oldPath)

  借鉴:解决途径 中的代码:

bubuko.com,布布扣
 1 function upload(response, request) {
 2   console.log("Request handler ‘upload‘ was called.");
 3   var form = new formidable.IncomingForm();
 4   form.uploadDir = "tmp"
 5   console.log("about to parse");
 6   form.parse(request, function(error, fields, files) {
 7     console.log("parsing done");
 8     console.log("F.U.P: " + files.upload.path);
 9     setTimeout(function(){
10     try{
11         fs.renameSync(files.upload.path, "./tmp/test.png");
12     }catch(e){
13         console.log(e);
14     }
15     response.writeHead(200, {"Content-Type": "text/html"});
16     response.write("received image:<br/>");
17     response.write("<img src=‘/show‘ />");
18     response.end();
19     },1000
20     );
21   });
22 }
View Code

3.运行错误 Error: ENOENT( 图片目录放置的问题)

  借鉴:解决途径

安装出错

bubuko.com,布布扣

借鉴: http://www.dedecms.com/knowledge/web-based/javascript-ajax/2012/0723/3484.html

最后的解决办法是:以管理员身份打开命令符,然后去安装,没想到成功了。记录忘记保存了,因为不知道可不可以用,现在证明可用。

bubuko.com,布布扣

 后面为啥还会有这个??

bubuko.com,布布扣

 途中还遇到个这样的问题  Error:listen EADDRINUSE 看到下面的解释就知道发生什么事了。。

bubuko.com,布布扣

CSS中的2个重要概念块状元素和内联元素 参考资料:来源

 对JS中的prototype的理解

 event.stopPropagation() 方法的理解:

 不再派发事件。

 终止事件在传播过程的捕获、目标处理或起泡阶段进一步传播。调用该方法后,该节点上处理该事件的处理程序将被调   用,事件不再被分派到其他节点。

//显示表情
  _showEmoji: function(msg) {
    var match, result = msg,
        reg = /\[emoji:\d+\]/g,
        emojiIndex,
        totalEmojiNum = document.getElementById(‘emojiWrapper‘).children.length;
    while (match = reg.exec(msg)) {
        emojiIndex = match[0].slice(7, -1);
        if (emojiIndex > totalEmojiNum) {
            result = result.replace(match[0], ‘[X]‘);
        } else {
            result = result.replace(match[0], ‘<img class="emoji" src="../content/emoji/‘ + emojiIndex + ‘.gif" />‘);
        };
    };
    return result;
}

从中学到的知识点有

1.reg.exec()

2.slice()

3.replace()

 GitHub代码更新问题bubuko.com,布布扣

借鉴资料http://blog.csdn.net/shiren1118/article/details/7761203

 

Codeship初次见面:http://blog.codeship.io/2014/04/03/continuous-deployment-modulus-github-nodejs.html

Heroku的初次见面:https://devcenter.heroku.com/articles/getting-started-with-nodejs

http://www.oschina.net/question/12_17345  Node.js MVC框架学习

1.exports 相当于C#中的publish,当这个模块被require导入时,exports后的方法可以被访问到,具体看一个node的模块导入系统:

//test.js
var myPrivate = ‘私有‘;
exports.myPublish = ‘公开‘;
this.myPublish2 = ‘this也可以哦‘;
console.log(‘test.js loaded \n‘);

执行结果:

bubuko.com,布布扣

从结果中我们可以看出exports和this下的变量在外部导入模块后,可以被外部访问到,而var定义的变量只能在脚本内部访问。  从mytest2结果还可以看出,第二次require导入test模块时,并没有打印"test.js loaded",因为require导入模块的时候,会先从require.cache中检查模块是否已经加载,如没有,才会从硬盘中查找模块脚本并加载。require支持相对路径查找模块,例如require(‘./test‘)中的"./"就代表在当前目录下查找。如果不是相对路径,例如require(‘http‘),node则会到require.paths中去查找,看下自己的系统require.paths为:

bubuko.com,布布扣

这个要等等了,不知道为啥是这个了。。。

 

 

 

Node学习

标签:des   style   blog   http   ar   io   color   os   sp   

原文地址:http://www.cnblogs.com/wj204/p/3643461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!