node 小知识

福尔摩斯对我笑 2018-11-29 6687 次 1687条

electron 屏蔽错误,可捕捉进程错误

// //捕获错误
process.on('uncaughtException', function(err) {
console.log(err.stack);
console.log('NOT exit...');
});

###  FTP

同一FTP同一IP不能超过8个链接

### 递归执行,解决node并发数问题

"use strict"
const request = require('request')
const fs = require('fs')

const arr = [
    'http://path.to/img1.jpg',
    'http://path.to/img2.jpg',
    'http://path.to/img3.jpg',
    ...
    'http://path.to/img498.jpg',
    'http://path.to/img499.jpg',
    'http://path.to/img500.jpg'
]

const download = (arr)=>{
    src = arr.pop();
    //下载图片
    const ws = fs.createWriteStream('./download/'+src.split('/').pop());
    ws.on('close', ()=>{
        console.log('下载完成')
        if (arr.length>0)
            return download(arr);
    })
    request(src).pipe(ws);
}

封装基本的表单验证类 -》 formVaildate

const formVaildate = (arr)=>{
    for(let i = 0; i < arr.length; i++){
        //判空
        if(arr[i].required)
        {
            if(arr[i].data == null || arr[i].data == '')
            {                
                arr[i].required()
                return 0;
            }
        }
        //正则
        if( arr[i].regExp && arr[i].regExp.regVal.test(arr[i].data) === false )
        {
            arr[i].regExp.callback();
            return 0;
        }
    }


    return true;
}

module.exports =  formVaildate

使用方法:

const userInfo = vaildate([
        {
            data: gender,
            required: ()=>{
                resJson.code = 1;
                resJson.msg = '请填写性别';
                res.json(resJson);
            },
            regExp:{
                regVal: /\d/,
                callback: () => {
                    resJson.code = 1;
                    resJson.msg = '性别格式有误';
                    res.json(resJson);
                }
            }
        },
        {
            data: year,
            required: ()=>{
                resJson.code = 1;
                resJson.msg = '请填写年份';
                res.json(resJson);
            }
        }
])

nvm使用

下载安装: https://github.com/coreybutler/nvm-windows/releases

找到安装目录,打开settings.txt,将下面的配置写到文件


node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

// nvm list // 你本机中所有的node的版本列表

// nvm install latest // 安装最新版本

// nvm install 4.8.4 // 安装指定版本

// nvm use 10.8.0 // 当前使用版本

nvm arch [32|64]: 显示node是运行在32位还是64位模式。指定32或64来覆盖默认体系结构。

-nvm install <version> [arch]:该可以是node.js版本或最新稳定版本latest。(可选[arch])指定安装32位或64位版本(默认为系统arch)。设置[arch]为all以安装32和64位版本。在命令后面添加–insecure,可以绕过远端下载服务器的SSL验证。

nvm list [available]:列出已经安装的node.js版本。可选的available,显示可下载版本的部分列表。这个命令可以简写为nvm ls [available]。

nvm on: 启用node.js版本管理。

nvm off: 禁用node.js版本管理(不卸载任何东西)

nvm proxy [url]: 设置用于下载的代理。留[url]空白,以查看当前的代理。设置[url]为none删除代理。

nvm node_mirror [url]:设置node镜像,默认为https://nodejs.org/dist/.。可以设置为淘宝的镜像https://npm.taobao.org/mirrors/node/

nvm npm_mirror [url]:设置npm镜像,默认为https://github.com/npm/npm/archive/。可以设置为淘宝的镜像https://npm.taobao.org/mirrors/npm/

nvm uninstall <version>: 卸载指定版本的nodejs。

nvm use [version] [arch]: 切换到使用指定的nodejs版本。可以指定32/64位[arch]。

-nvm use <arch>:将继续使用所选版本,但根据提供的值切换到32/64位模式

nvm root [path]: 设置 nvm 存储node.js不同版本的目录 ,如果未设置,将使用当前目录。

-nvm version: 显示当前运行的nvm版本,可以简写为nvm v

Busyboy文件上传模块使用

若想在文件上传途中,做检测,并返回信息,必须进行文件释放

stream.resume();

递归读取文件大小



  function readFileList(path, filesList) {
    console.log(path);
    var files = fs.readdirSync(path);
    files.forEach(function (itm, index) {
        var stat = fs.statSync(path + "/"+ itm);
        if (stat.isDirectory()) {
        //递归读取文件
            readFileList(path + "/" + itm , filesList)
        } else {
            var {size} =  fs.statSync(path + "/"+ itm);
            filesList.push(size);
        }


    })
}
标签: 无

非特殊说明,本博所有文章均为博主原创。

头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 1687 条评论 1


  1. tienda hippie low cost

    Also I believe that mesothelioma is a exceptional form of most cancers that is often found in people previously exposed to asbestos. Cancerous cellular material form inside mesothelium, which is a protective lining that covers the majority of the body’s areas. These cells ordinarily form inside lining from the lungs, abdominal area, or the sac that encircles the heart. Thanks for expressing your ideas.

    回复 2020年2月26日
  2. Electric Off Road Bikes

    Just wanna comment on few general things, The website pattern is perfect, the written content is rattling excellent : D.

    回复 2020年2月26日
  3. piss

    Hi there! This blog post could not be written much better! Going through this article reminds me of my previous roommate! He always kept talking about this. I will send this post to him. Fairly certain he will have a very good read. Thank you for sharing!

    回复 2020年2月26日
  4. nba streams

    Thank you for sharing excellent informations. Your website is so cool. I am impressed by the details that you have on this website. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched all over the place and just couldn’t come across. What a perfect web-site.

    回复 2020年2月26日
  5. dummy

    Aw, this was a very good post. Taking a few minutes and actual effort to create a great article… but what can I say… I hesitate a whole lot and never manage to get nearly anything done.

    回复 2020年2月26日
  6. jasa pembuatan sbu

    This is a good tip especially to those fresh to the blogosphere. Short but very precise info… Thanks for sharing this one. A must read article!

    回复 2020年2月26日
  7. self car wash

    Rinse off your entire car with a hose, generating sure you get any debris out from underneath the wiper blades.

    回复 2020年2月26日
  8. ass fuck

    This is a very good tip especially to those fresh to the blogosphere. Simple but very accurate info… Appreciate your sharing this one. A must read article!

    回复 2020年2月26日
  9. 바카라 사이트

    It’s really a great and useful piece of information. I am glad that you simply shared
    this helpful information with us. Please stay us informed like this.
    Thank you for sharing.

    回复 2020年2月26日
  10. 온 카지노

    I was recommended this web site by my cousin. I’m not sure whether
    this post is written by him as no one else know such detailed about my difficulty.
    You are incredible! Thanks!

    回复 2020年2月26日
  11. ass fuck

    Hi there! This post couldn’t be written any better! Looking through this post reminds me of my previous roommate! He always kept preaching about this. I most certainly will send this post to him. Fairly certain he’ll have a great read. Many thanks for sharing!

    回复 2020年2月26日
  12. nigger

    Oh my goodness! Awesome article dude! Many thanks, However I am encountering problems with your RSS. I don’t understand the reason why I can’t join it. Is there anybody having the same RSS problems? Anyone that knows the solution can you kindly respond? Thanks!!

    回复 2020年2月26日
  13. cocksucker

    You made some good points there. I checked on the net to find out more about the issue and found most people will go along with your views on this website.

    回复 2020年2月26日
  14. shit

    You’re so awesome! I do not believe I’ve read something like that before. So nice to find someone with a few original thoughts on this topic. Seriously.. thanks for starting this up. This site is something that is required on the internet, someone with some originality!

    回复 2020年2月26日
  15. penisfucker

    Next time I read a blog, Hopefully it won’t fail me as much as this one. I mean, I know it was my choice to read through, however I genuinely thought you would probably have something helpful to talk about. All I hear is a bunch of crying about something you could possibly fix if you weren’t too busy seeking attention.

    回复 2020年2月26日
  16. cockfucker

    This is a topic that is close to my heart… Cheers! Where are your contact details though?

    回复 2020年2月26日
  17. lesbians

    That is a great tip particularly to those fresh to the blogosphere. Brief but very precise information… Appreciate your sharing this one. A must read article!

    回复 2020年2月26日
  18. fag

    bookmarked!!, I like your blog!

    回复 2020年2月26日
  19. 하남 출장업소〖카톡: Mo46〗m oo27.c0M콜걸강추릉콜걸샵Y╅╖2019-02-20-04-54하남╂AIJ►오피출장샵안마⇔출장샵강추♡출장소이스홍성➚하남

    I need to to thank you for this excellent read!! I absolutely loved every bit of it. I have you saved as a favorite to look at new stuff you post…

    回复 2020年2月26日
  20. 더킹카지노

    Does it actually matter? To me it doesn’t. I’m extra concerned with the relevancy
    of the message. Utilizing the portion of the teachings that make sense to me, has supplied some fantastic life altering experiences. http://aboutjuries.org/__media__/js/netsoltrademark.php?d=siterank.aurorius.com%2Findex.php%3Fa%3Dstats%26u%3Dluellagiltner

    回复 2020年2月26日
  21. 더킹카지노

    Does it actually matter? To me it doesn’t. I’m extra concerned with the
    relevancy of the message. Utilizing the portion of the teachings that make sense to me,
    has supplied some fantastic life altering experiences. http://aboutjuries.org/__media__/js/netsoltrademark.php?d=siterank.aurorius.com%2Findex.php%3Fa%3Dstats%26u%3Dluellagiltner

    回复 2020年2月26日
  22. lesbians

    You’re so cool! I don’t believe I’ve truly read something like that before. So great to discover someone with original thoughts on this topic. Really.. thank you for starting this up. This site is something that is needed on the internet, someone with a little originality!

    回复 2020年2月26日
  23. penisfucker

    Your style is really unique compared to other people I have read stuff from. I appreciate you for posting when you’ve got the opportunity, Guess I will just bookmark this page.

    回复 2020年2月26日
  24. http://www.ufrgs.br/seerbio/ojs/index.php/rbb/user/viewPublicProfile/214071

    Excellent beat ! I would like to apprentice at the same time as you amend your site, how can i subscribe
    for a blog site? The account helped me a acceptable deal. I
    had been tiny bit familiar of this your broadcast offered brilliant transparent concept

    回复 2020年2月26日
  25. bloody hell

    That is a great tip particularly to those new to the blogosphere. Simple but very precise info… Appreciate your sharing this one. A must read article!

    回复 2020年2月26日
  26. 188bet

    Hey There. I found your blog using msn. This is a really well written article.
    I will be sure to bookmark it and come back to read more
    of your useful information. Thanks for the post.
    I’ll certainly return.

    回复 2020年2月26日
  27. xxx mom porn videos

    Hello! Do you know if they make any plugins to assist
    with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Thanks!

    回复 2020年2月26日
  28. orgasm

    Oh my goodness! Impressive article dude! Thank you so much, However I am experiencing problems with your RSS. I don’t understand why I can’t subscribe to it. Is there anyone else getting the same RSS issues? Anybody who knows the answer will you kindly respond? Thanks!!

    回复 2020年2月26日
  29. boong

    This is a topic that is close to my heart… Take care! Exactly where are your contact details though?

    回复 2020年2月25日
  30. modern construction co

    Howdy just wanted to give you a brief heads up and let you know a few of the images aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different internet browsers and both show the same results.

    回复 2020年2月25日
  31. penisfucker

    After looking at a handful of the articles on your blog, I seriously like your technique of blogging. I saved as a favorite it to my bookmark site list and will be checking back in the near future. Please check out my website too and let me know your opinion.

    回复 2020年2月25日
  32. assshole

    This site was… how do I say it? Relevant!! Finally I’ve found something which helped me. Many thanks!

    回复 2020年2月25日
  33. pussy

    Good info. Lucky me I came across your site by accident (stumbleupon). I’ve book marked it for later!

    回复 2020年2月25日
  34. douche

    Hi, I do believe this is an excellent website. I stumbledupon it 😉 I will revisit once again since i have saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to guide others.

    回复 2020年2月25日
  35. w88

    You should take part in a contest for one of the most useful websites online.
    I’m going to highly recommend this blog!

    回复 2020年2月25日
  36. adult frienf finder

    Thank you a lot for sharing this with all of us you actually
    know what you are talking about! Bookmarked.

    Please also consult with my website =). We could
    have a link alternate arrangement among us

    回复 2020年2月25日
  37. god damn

    I could not resist commenting. Very well written!

    回复 2020年2月25日
  38. black cock

    Hello! I just want to give you a big thumbs up for the great information you have here on this post. I’ll be returning to your site for more soon.

    回复 2020年2月25日
  39. ass fuck

    Everyone loves it whenever people come together and share ideas. Great site, keep it up!

    回复 2020年2月25日
  40. hore

    This is a topic which is near to my heart… Many thanks! Where are your contact details though?

    回复 2020年2月25日
  41. negro

    This site was… how do I say it? Relevant!! Finally I’ve found something which helped me. Thank you!

    回复 2020年2月25日
  42. w88

    Great website you have here but I was wondering if you knew
    of any forums that cover the same topics discussed here?

    I’d really like to be a part of online community where I can get opinions from other knowledgeable people that share the same interest.
    If you have any recommendations, please let me
    know. Thank you!

    回复 2020年2月25日
  43. lexus888 sabung ayam

    My spouse and I stumbled over here from a different website
    and thought I might check things out. I like what I see so now i’m following you.
    Look forward to checking out your web page again.

    回复 2020年2月25日
  44. Mount Abu escorts

    Very interesting details you have noted , thankyou for posting . “Great is the art of beginning, but greater is the art of ending.” by Henry Wadsworth Longfellow.

    回复 2020年2月25日
  45. buy weed in uk

    Excellent site. Plenty of helpful info here. I am sending it to some buddies ans also sharing in delicious. And obviously, thank you in your effort!

    回复 2020年2月25日
  46. shit

    There’s definately a lot to know about this subject. I like all the points you’ve made.

    回复 2020年2月25日
  47. assshole

    An intriguing discussion is definitely worth comment. I do think that you should publish more on this issue, it might not be a taboo subject but typically folks don’t speak about these issues. To the next! Best wishes!!

    回复 2020年2月25日
  48. cash advance instant approval

    The processing is completed much quicker, occasionally instantaneously, as well as the amount you borrow
    is deposited with the next bank day time
    from the lenders on the borrowers account. Today,
    most people are so busy in life, that they can hardly have got time
    for you to waste on faxing documents when trying to get a
    loan. By and large though, most lender sites offer secure online pay day
    loans so your probability of getting hoodwinked are fairly minimal.

    回复 2020年2月25日