node 小知识

福尔摩斯对我笑 2018-11-29 50962 次 7243条

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
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 7243 条评论 1


  1. indotogel hari ini

    I was recommended this blog by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my difficulty. You’re wonderful! Thanks!

    回复 2019年12月12日
  2. Smart Start Collective

    Nice post. I learn something totally new and challenging on sites I stumbleupon on a daily basis. It’s always helpful to read through articles from other writers and use a little something from other sites.

    回复 2019年12月12日
  3. IELFACE

    There is certainly a great deal to learn about this topic. I like all of the points you have made.

    回复 2019年12月12日
  4. social media marketing

    Howdy just wanted to give you a quick 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 outcome.

    回复 2019年12月11日
  5. SapidAgency

    Sapid Agency is a Search Engine Optimization company in New York City that provides SEO Services. Their proprietary SEO strategies help struggling websites and aspiring business owners to rank their websites higher in multiple search engines like Google , Yahoo and Bing. They provide local and gmb map ranking for businesses in NYC and many other local areas. Find more at https://www.sapidagency.com/

    回复 2019年12月11日
  6. Women Tops

    It’s actually a cool and useful piece of info. I’m glad that you shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.

    回复 2019年12月11日
  7. ดูสนุกเกอร์สด

    Wonderful goods from you, man. I have understand your stuff previous to and you’re just extremely wonderful. I actually like what you’ve acquired here, really like what you are saying and the way in which you say it. You make it entertaining and you still take care of to keep it wise. I can’t wait to read much more from you. This is actually a wonderful website.

    回复 2019年12月11日
  8. Gay Porn

    Whats up very cool site!! Guy .. Excellent .. Wonderful .. I’ll bookmark your blog and take the feeds additionally…I am satisfied to seek out a lot of helpful info right here in the put up, we need develop extra techniques on this regard, thanks for sharing. . . . . .

    回复 2019年12月11日
  9. BeTransformed

    I was very happy to find this website. I wanted to thank you for ones time due to this fantastic read!! I definitely enjoyed every part of it and i also have you saved as a favorite to see new stuff in your blog.

    回复 2019年12月11日
  10. TV stand assembly service

    I have to show some thanks to the writer for bailing me out of this instance. As a result of looking throughout the internet and obtaining concepts which are not beneficial, I believed my entire life was over. Existing minus the approaches to the difficulties you have sorted out all through this post is a serious case, as well as those that might have in a wrong way affected my career if I had not noticed your blog post. Your primary ability and kindness in handling all areas was precious. I’m not sure what I would’ve done if I had not come upon such a thing like this. It’s possible to at this time look forward to my future. Thanks a lot so much for your impressive and amazing help. I will not be reluctant to endorse your web site to anybody who would need care on this subject matter.

    回复 2019年12月11日
  11. cashmere wrap

    This is the suitable blog for anyone who desires to search out out about this topic. You notice a lot its virtually hard to argue with you (not that I really would want…HaHa). You positively put a new spin on a subject thats been written about for years. Nice stuff, simply great!

    回复 2019年12月10日
  12. Wellbeing

    I have been exploring for a little for any high-quality articles or weblog posts in this kind of area . Exploring in Yahoo I finally stumbled upon this web site. Studying this info So i am happy to show that I have a very good uncanny feeling I discovered exactly what I needed. I so much definitely will make certain to don’t fail to remember this website and give it a look on a constant basis.

    回复 2019年12月10日
  13. dresser assembly service

    I am extremely impressed along with your writing abilities as smartly as with the format for your blog. Is that this a paid subject or did you modify it yourself? Anyway keep up the nice high quality writing, it is uncommon to peer a nice weblog like this one nowadays..

    回复 2019年12月10日
  14. Travel Halong Bay

    Merely wanna input on few general things, The website layout is perfect, the subject material is very superb : D.

    回复 2019年12月10日
  15. house cleaning Las Vegas

    Hi, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of spam remarks? If so how do you reduce it, any plugin or anything you can recommend? I get so much lately it’s driving me mad so any assistance is very much appreciated.

    回复 2019年12月9日
  16. house cleaning Las Vegas

    We absolutely love your blog and find many of your post’s to be exactly I’m looking for. Would you offer guest writers to write content in your case? I wouldn’t mind writing a post or elaborating on some of the subjects you write concerning here. Again, awesome weblog!

    回复 2019年12月9日
  17. Pool table installation

    Thanks a bunch for sharing this with all people you actually recognise what you are talking approximately! Bookmarked. Please additionally consult with my site =). We will have a hyperlink trade contract between us!

    回复 2019年12月9日
  18. จับ บ่อน การ พนัน สมุทรปราการ

    My brother recommended I might like this website. He was entirely right. This post truly made my day. You cann’t imagine just how much time I had spent for this information! Thanks!

    回复 2019年12月9日
  19. i99BET

    I was extremely pleased to uncover this great site. I need to to thank you for ones time due to this fantastic read!! I definitely enjoyed every bit of it and I have you saved as a favorite to check out new information in your site.

    回复 2019年12月9日
  20. Furniture assembly help

    Great work! That is the kind of info that are supposed to be shared across the web. Disgrace on Google for no longer positioning this submit higher! Come on over and consult with my web site . Thank you =)

    回复 2019年12月9日
  21. i99BET

    I’d like to thank you for the efforts you’ve put in penning this website. I really hope to view the same high-grade blog posts from you in the future as well. In fact, your creative writing abilities has encouraged me to get my own, personal blog now 😉

    回复 2019年12月9日
  22. Furniture installers

    There are some interesting points in time in this article but I don’t know if I see all of them center to heart. There may be some validity but I will take hold opinion till I look into it further. Good article , thanks and we want extra! Added to FeedBurner as properly

    回复 2019年12月8日
  23. Furniture assembly help

    Hi are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding expertise to make your own blog? Any help would be really appreciated!

    回复 2019年12月8日
  24. UFABET

    I’m impressed, I have to admit. Seldom do I come across a blog that’s equally educative and engaging, and without a doubt, you have hit the nail on the head. The issue is something too few people are speaking intelligently about. I am very happy that I came across this during my hunt for something regarding this.

    回复 2019年12月7日
  25. ultimate installation

    Normally I don’t read article on blogs, but I wish to say that this write-up very forced me to check out and do so! Your writing taste has been surprised me. Thanks, quite great article.

    回复 2019年12月7日
  26. Delta installation

    Real fantastic information can be found on web site. “I can think of nothing less pleasurable than a life devoted to pleasure.” by John D. Rockefeller.

    回复 2019年12月7日
  27. 스포츠티비

    Thanks for the sensible critique. Me and my neighbor were just preparing to do a little research on this. We got a grab a book from our area library but I think I learned more clear from this post. I’m very glad to see such great information being shared freely out there.

    回复 2019年12月6日
  28. AMI installation

    You have observed very interesting points ! ps decent website . “To grow mature is to separate more distinctly, to connect more closely.” by Hugo Von Hofmannsthal.

    回复 2019年12月6日
  29. udaipur escorts

    Excellent read, I just passed this onto a friend who was doing a little research on that. And he actually bought me lunch as I found it for him smile Thus let me rephrase that: Thank you for lunch! “Without friends no one would choose to live, though he had all other goods.” by Aristotle.

    回复 2019年12月6日
  30. togel hk

    I was examining some of your blog posts on this internet site and I think this website is very informative ! Retain putting up.

    回复 2019年12月6日
  31. graphic design

    great points altogether, you just won a new reader. What might you recommend about your put up that you made some days in the past? Any positive?

    回复 2019年12月5日
  32. Encontros de Sexo

    You ought to be a part of a contest for one of the best websites on the web. I most certainly will recommend this blog!

    回复 2019年12月5日
  33. semsi

    I must thank you for the efforts you’ve put in penning this blog. I’m hoping to see the same high-grade content from you later on as well. In fact, your creative writing abilities has inspired me to get my own blog now 😉

    回复 2019年12月4日
  34. i99bet

    Good information. Lucky me I recently found your site by accident (stumbleupon). I’ve saved it for later!

    回复 2019年12月4日
  35. i99bet

    Good post. I learn something new and challenging on websites I stumbleupon everyday. It’s always useful to read articles from other authors and practice something from other websites.

    回复 2019年12月3日
  36. John Deere Technical Manuals

    You produced some decent points there. I looked on the net to the issue and discovered most people goes together with along with your website.

    回复 2019年12月2日
  37. Celsa Sulivan

    It’s nearly impossible to find experienced people in this particular topic, but you seem like you know what you’re talking about! Thanks

    回复 2019年12月2日
  38. Clay Zimmerman

    This website certainly has all of the information and facts I needed about this subject and didn’t know who to ask.

    回复 2019年12月2日
  39. Tworzenie Stron Www Gorzów Wlkp

    You have brought up a very good details , thanks for the post.

    回复 2019年11月30日
  40. Hector Mertz

    I will be brand-new to blogging and also loved your internet site. I will bookmark your blog and keep checking get you started. Thanks for sharing your internet site.

    回复 2019年11月28日
  41. Sylvie Rettkowski

    I do not even understand how I stopped up here, however I thought this submit was once good. I do not realize who you’re but certainly you are going to a well-known blogger for those who aren’t already Cheers!

    回复 2019年11月28日
  42. view publisher site

    I just want to say I’m newbie to blogging and site-building and actually savored you’re web-site. Probably I’m want to bookmark your site . You actually come with great article content. Cheers for revealing your website page.

    回复 2019年11月24日
  43. StevDede

    Viagra Para El Deporte cialis tablets for sale Acheter Du Cytotec En Ligne Sans Ordonnance Doxycycline Acne Xenical No Prescription

    回复 2019年11月22日