最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

什么是在Node.js的(快递框架)处理文本的有效途径?

IT培训 admin 7浏览 0评论

什么是在Node.js的(快递框架)处理文本的有效途径?

所以我有一个Web服务器这将根据用户的值发送HTML。我有一个小处理这将读取现有的文件(包括密码),并允许用户enter.I't工作但有一些可能性。即有时它会不会有时工作了。

剪断,它这将工作的每一次:

app.all('/acceptForm',function(req,res){
  if (req.method === 'POST') {
        let body = '';
        var match = 0;
        req.on('data', chunk => {
            body += chunk.toString();
        });
        req.on('end', () => {
            //get the uid to compare later on in the program 
          uid = parse(body).uid_text;
         //read the UID file.
          var lineReader = require('readline').createInterface({
            input: require('fs').createReadStream(__dirname+'/uid.txt')
            ... 
// write the other information to a file which would be later on re -opened again to read the things again
which have the file name of the 'uid'


 firstname =  parse(body).first_name;
               lastname = parse(body).last_name;
                mothername = parse(body).mother_name;
                fathername = parse(body).father_name;
                email = parse(body).email;
                profession = parse(body).profession_text;
                gender = parse(body).gender;
                language = parse(body).lang_0;
                married = parse(body).married;
                birthday =  parse(body).dateofbirth;
             //write the UID and other things to the text file
             console.log(language);
             var fileContent = uid +'|' + firstname +'|'+ lastname +'|' + mothername +'|' + fathername +'|' + email+'|' + profession+'|' + gender+'|' + married+'|' +birthday + '|';
               var filepath = __dirname+"/users/"+uid + ".txt";

               fs.writeFile(filepath, fileContent, (err)


...
            lineReader.on('line', function (line) {
           if(line == uid) {
                    // if the uid is found...
            res.cookie('name',uid, {signed: true}); //write the  uid as a cookie back
            res.sendFile(__dirname+'/CE/ENG/Kids.html');
             }   else{
             //some failure message 
}  
          });

          });
  } 
}

这个问题一旦被作为用户发送这一点,改变到另一个文件与服务器失去跟踪与我添加了相同的系统cookies.Now存在安全风险,以及有更多的风险client.To抵消。

处理来自kids.html存储在另一个文件的响应....(具有非常低的概率,它的作品是成功的)。

app.all('/return',function(req,res){
  if (req.method === 'POST') {


  //read the UID file.
  var lineReader = require('readline').createInterface({
    input: require('fs').createReadStream(__dirname+'/uid.txt')
  });
  //Handling the information from the client.
  lineReader.on('line', function (line) {
   if(line == req.signedCookies['name']) {
     //uid matches with the database 
     fs.readdir( __dirname+"/users/", (err, files) => {
      files.forEach(file => {
       if(file == req.signedCookies['name'] + ".txt"){
        let questiondata = '';
        req.on('data', chunk => {
            questiondata += chunk.toString();

        });


        req.on('end', () => {
          var cleaneddata = questiondata.split('%2C'); //%2C is a spliting term {array}
          cleaneddata.splice(0,1);

          //add the question data to another file 
          fs.appendFile( __dirname+"/users/" + req.signedCookies['name'] + ".txt",cleaneddata.toString() + "\r\n", function (err) {  //writes inside the temp file for the questions
            if (err) throw err;

            fs.createReadStream( __dirname+"/users/" + req.signedCookies['name'] + ".txt").pipe(fs.createWriteStream( __dirname+'/users.txt', {flags: 'a'}));

          fs.unlink( __dirname+"/users/"+ req.signedCookies['name'] + ".txt",function(err){
            if(err) return console.log(err);
            res.clearCookie("name");


          });
          });


        });


       } 
      });
    })
    } 


回答如下:

作为一个建议:

var lineReader = require('linebyline');

app.post('/return' , (req, res) => {

  var cookie = req.signedCookies['name'];

  // check cookie
  console.log(cookie);


  // red the UID file:
  rl = readline(__dirname + 'uid.txt');
  // BTW: Why no database?!

  rl.on('line', function(line, lineCount, byteCount) {
    if (line === cookie) {
      // ...
    }
  })
  .on('error', function(e) {
    // something went wrong
    res.status(500).json({
      error: err
    })
  });

  // Here you are filling some txt files with data out of your form data.. 
  // I highly suggest using a database instead of using your local directory
  // structure and txt files.

})


什么是在Node.js的(快递框架)处理文本的有效途径?

所以我有一个Web服务器这将根据用户的值发送HTML。我有一个小处理这将读取现有的文件(包括密码),并允许用户enter.I't工作但有一些可能性。即有时它会不会有时工作了。

剪断,它这将工作的每一次:

app.all('/acceptForm',function(req,res){
  if (req.method === 'POST') {
        let body = '';
        var match = 0;
        req.on('data', chunk => {
            body += chunk.toString();
        });
        req.on('end', () => {
            //get the uid to compare later on in the program 
          uid = parse(body).uid_text;
         //read the UID file.
          var lineReader = require('readline').createInterface({
            input: require('fs').createReadStream(__dirname+'/uid.txt')
            ... 
// write the other information to a file which would be later on re -opened again to read the things again
which have the file name of the 'uid'


 firstname =  parse(body).first_name;
               lastname = parse(body).last_name;
                mothername = parse(body).mother_name;
                fathername = parse(body).father_name;
                email = parse(body).email;
                profession = parse(body).profession_text;
                gender = parse(body).gender;
                language = parse(body).lang_0;
                married = parse(body).married;
                birthday =  parse(body).dateofbirth;
             //write the UID and other things to the text file
             console.log(language);
             var fileContent = uid +'|' + firstname +'|'+ lastname +'|' + mothername +'|' + fathername +'|' + email+'|' + profession+'|' + gender+'|' + married+'|' +birthday + '|';
               var filepath = __dirname+"/users/"+uid + ".txt";

               fs.writeFile(filepath, fileContent, (err)


...
            lineReader.on('line', function (line) {
           if(line == uid) {
                    // if the uid is found...
            res.cookie('name',uid, {signed: true}); //write the  uid as a cookie back
            res.sendFile(__dirname+'/CE/ENG/Kids.html');
             }   else{
             //some failure message 
}  
          });

          });
  } 
}

这个问题一旦被作为用户发送这一点,改变到另一个文件与服务器失去跟踪与我添加了相同的系统cookies.Now存在安全风险,以及有更多的风险client.To抵消。

处理来自kids.html存储在另一个文件的响应....(具有非常低的概率,它的作品是成功的)。

app.all('/return',function(req,res){
  if (req.method === 'POST') {


  //read the UID file.
  var lineReader = require('readline').createInterface({
    input: require('fs').createReadStream(__dirname+'/uid.txt')
  });
  //Handling the information from the client.
  lineReader.on('line', function (line) {
   if(line == req.signedCookies['name']) {
     //uid matches with the database 
     fs.readdir( __dirname+"/users/", (err, files) => {
      files.forEach(file => {
       if(file == req.signedCookies['name'] + ".txt"){
        let questiondata = '';
        req.on('data', chunk => {
            questiondata += chunk.toString();

        });


        req.on('end', () => {
          var cleaneddata = questiondata.split('%2C'); //%2C is a spliting term {array}
          cleaneddata.splice(0,1);

          //add the question data to another file 
          fs.appendFile( __dirname+"/users/" + req.signedCookies['name'] + ".txt",cleaneddata.toString() + "\r\n", function (err) {  //writes inside the temp file for the questions
            if (err) throw err;

            fs.createReadStream( __dirname+"/users/" + req.signedCookies['name'] + ".txt").pipe(fs.createWriteStream( __dirname+'/users.txt', {flags: 'a'}));

          fs.unlink( __dirname+"/users/"+ req.signedCookies['name'] + ".txt",function(err){
            if(err) return console.log(err);
            res.clearCookie("name");


          });
          });


        });


       } 
      });
    })
    } 


回答如下:

作为一个建议:

var lineReader = require('linebyline');

app.post('/return' , (req, res) => {

  var cookie = req.signedCookies['name'];

  // check cookie
  console.log(cookie);


  // red the UID file:
  rl = readline(__dirname + 'uid.txt');
  // BTW: Why no database?!

  rl.on('line', function(line, lineCount, byteCount) {
    if (line === cookie) {
      // ...
    }
  })
  .on('error', function(e) {
    // something went wrong
    res.status(500).json({
      error: err
    })
  });

  // Here you are filling some txt files with data out of your form data.. 
  // I highly suggest using a database instead of using your local directory
  // structure and txt files.

})


发布评论

评论列表 (0)

  1. 暂无评论