如何将 Node.js 文件系统设置为 ionic 项目



我想删除客户端的文件夹/文件(使用 javascript/Jquery/AngularJS1(。我正在搜索,最后我开始使用 Node.js它可以在站点链接中完成。现在我没有得到如何使用任何一种语言设置 Node.js fs(文件系统(。(首选语言是AngularJS1(。寻找解决方案。提前谢谢。

var express = require('express');
var app = express();
var fs   = require("fs");
var bodyParser = require('body-parser')
app.use( bodyParser.json() );       // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({     // to support URL-encoded bodies
  extended: true
}));


app.get('*', function (req, res) {
    console.log(req.path);
   var path = req.path;
   if(req.path == '/'){
     res.sendFile( __dirname + "/" + "index.html" );
   }else
   {
     res.sendFile( __dirname + req.path);
   }
});
app.post('/app',function (req, res) {
   console.log(req.body)
   var action = req.body.action;
   var data   = req.body.data;
   var fname  = req.body.fileName;
switch(action) {
    
    case 'upLoad':
       function decodeBase64Image(dataString) {
               var matches = dataString.match(/^data:([A-Za-z-+/]+);base64,(.+)$/),
            response = {};
        if (matches.length !== 3) {
            return new Error('Invalid input string');
        }
        response.type = matches[1];
        response.data = new Buffer(matches[2], 'base64');
        return response;
        };
        var imageBuffer = decodeBase64Image(data);
        var newPath = __dirname + "/app/images/" + fname;
        fs.writeFile(newPath, imageBuffer.data, function(err) {
                res.send({confirm : "uploaded" , filename:fname });
             });
   
     default:
       
}
})
var server = app.listen(8080, function () {
   var host = server.address().address
   var port = server.address().port
   console.log("Example app listening at http://%s:%s", host, port)
})

嗨,这是我使用过的应用程序文件夹。

在此服务器.js文件中,我包含节点.js模块并加载应用程序。

最新更新