zoukankan      html  css  js  c++  java
  • Nodejs note

    notes

    1.StormJs这个是用来干什么的?

    2.SIGINT(signal interapt)

    3.编译nodejs时,加上 -j 8(表示开启8个make的job?) 编译速度很快

    4.用NodeJs抓取非utf-8字符网页

    5.HTML5 canvas编程

    6.用递归的方式创建多级目录

    var http = require('http');
    // 创建所有目录
    var mkdirs = module.exports.mkdirs = function(dirpath, mode, callback) {
        path.exists(dirpath, function(exists) {
            if(exists) {
                    callback(dirpath);
            } else {
                    //尝试创建父目录,然后再创建当前目录
                    mkdirs(path.dirname(dirpath), mode, function(){
                            fs.mkdir(dirpath, mode, callback);
                    });
            }
        });
    };
    

    7.延迟http 响应

    var http = require('http');
    
    http.createServer(function(request, response){
       // Write Headers
       response.writeHead(200);//NOTE HERE
    
       // Write Hello World!
       response.write("Hello World!");
    
       // End Response after 5 seconds
       setTimeout(function(){ 
            response.end(); 
       }, 5000);
    
    }).listen(8000);
    

    上面的代码不能达到先输出 ”Hello World“ 的目的

    var http = require('http');
    
    http.createServer(function(request, response){
       // Write Headers
       response.writeHead(200, {'Content-Type': 'text/plain'});//改成这样以后就可以了。为什么呢?
    
       // Write Hello World!
       response.write("Hello World!");
    
       // End Response after 5 seconds
       setTimeout(function(){ 
            response.end(); 
       }, 5000);
    
    }).listen(8000);
    
  • 相关阅读:
    现代算法(一) 基因算法
    01-02周 学习总结
    Linux命令之touch详解
    Linux命令之umask详解
    Linux命令之wc详解
    Linux命令之stat详解
    Linux命令之tail详解
    Linux命令之head详解
    Linux命令之less详解
    Linux命令
  • 原文地址:https://www.cnblogs.com/wewe/p/2059717.html
Copyright © 2011-2022 走看看