zoukankan      html  css  js  c++  java
  • nodejs学习之模块:crypto和body-parser

    1:关于模块crypto;

    我在使用crypto.cpmpare(源码在下面),忘记了些第二个参数,导致老是出现'data and hash must be strings'

    找了好长一些时间,最后通过看源码,发现是第二个参数没写;

     1 /// compare raw data to hash
     2 /// @param {String} data the data to hash and compare
     3 /// @param {String} hash expected hash
     4 /// @param {Function} cb callback(err, matched) - matched is true if hashed data matches hash
     5 module.exports.compare = function(data, hash, cb) {
     6     if (data == null || data == undefined || hash == null || hash == undefined) {
     7         throw new Error('data and hash arguments required');
     8     } else if (typeof data !== 'string' || typeof hash !== 'string') {
     9         throw new Error('data and hash must be strings');
    10     }
    11 
    12     if (!cb) {
    13         throw new Error('callback required for async compare');
    14     } else if (typeof cb !== 'function') {
    15         throw new Error('callback must be a function');
    16     }
    17 
    18     return bindings.compare(data, hash, cb);
    19 };
    View Code

    2:关于模块body-parser;

    之前这个功能是作为express的中间件用得,如下:

    app.use(express.bodyParser())

    //现在已经没有和express绑定了,直接作为node的一个模块使用:

    var bodyParser = require('body-parser')

    如果不用这个,在req.body时根本找到不到数据。

     
  • 相关阅读:
    Search Insert Position
    Sum Root to Leaf Numbers
    String to Integer (atoi)
    Populating Next Right Pointers in Each Node
    Triangle
    Pascal's Triangle II
    Longest Consecutive Sequence
    属性透明度
    ul的列表符号在IE6下显示不全
    table的属性border-collapse 设置边框是否合并
  • 原文地址:https://www.cnblogs.com/wocn/p/4641108.html
Copyright © 2011-2022 走看看