如果包含反斜杠,则无法读取json属性

我试图从请求访问一个JSON,如: var files = req.files.fileData[0]; // This contains multiple file data // initially it is like [object object] for(var i=0; i<files.length; i++){ var fileDataArr = JSON.stringify(files[i]); console.log("**********fileDataArr : "+fileDataArr); var attachmentId = fileDataArr.name.attachmentId; console.log("id : "+attachmentId); } JSON结构是我得到,而控制台fileDataArr是: {"domain":null,"_events":{},"_eventsCount":0,"size":5056,"path":"C:\\Users\\k7000649\\AppData\\Local\\Temp\\8eb4f7b82b5646cef78f9989bb3353b1","name":"{\"fileName\":\"wiproNewIcon.png\",\"fileType\":\"image/png\",\"attachmentId\":\"99c148f3f5c1\",\"restrictedFileSize\":\"25690112 \"}","type":"image/png","hash":false,"lastModifiedDate":"2017-08-22T11:25:03.380Z","_writeStream":{"_writableState":{"objectMode":false,"highWaterMark":16384,"needDrain":false,"ending":true,"ended":true,"finished":true,"decodeStrings":true,"defaultEncoding":"utf8","length":0,"writing":false,"corked":0,"sync":false,"bufferProcessing":false,"writecb":null,"writelen":0,"bufferedRequest":null,"lastBufferedRequest":null,"pendingcb":0,"prefinished":true,"errorEmitted":false,"bufferedRequestCount":0,"corkedRequestsFree":{"next":null,"entry":null}},"writable":false,"domain":null,"_events":{},"_eventsCount":0,"path":"C:\\Users\\k7000649\\AppData\\Local\\Temp\\8eb4f7b82b5646cef78f9989bb3353b1","fd":null,"flags":"w","mode":438,"autoClose":true,"bytesWritten":5056,"closed":true},"length":5056,"filename":"{\"fileName\":\"wiproNewIcon.png\",\"fileType\":\"image/png\",\"attachmentId\":\"99c148f3f5c1\",\"restrictedFileSize\":\"25690112 \"}","mime":"image/png"} 结构是有效的,但反斜杠 我试图parsing的JSON删除反斜杠,但它会引发一个像SyntaxError:意外的令牌o的错误,当我试图从JSON访问任何数据(fileDataArr.name.attachmentId)它会引发一个错误,如: TypeError: Cannot read property 'attachmentId' of undefined at exports.xhr_upload_multi_attachment (D:\Harmony_Trunk\Development\Asset-Editor\build\harmony_development\routes\xhr_upload_attachment.js:122:39) 我尝试用正则expression式replace反斜杠(/ \ […]

Angular 4生产部署工作stream程

我和一位同事讨论了如何将angular度4应用程序部署到生产服务器。 如果可能的话,希望从社区那里得到实际的build议和指导。 前提1 在生产服务器上, git pull npm install {set up production configuration} ng build –prod –aot 在生产服务器上构build和编译 生产服务器硬件规格需要支持构build过程 托pipe服务器上需要添加空间以容纳node_modules git repo master分支没有编译代码,因此是一个“clean source repo” 前提2 在生产服务器上, git pull 在本地开发工作站上build立和编译生产代码将会更快 git repo master分支将保留已编译代码的部署快照 生产服务器仍然是一个有限的空间的128MB的RAM,因为它是服务的HTML,JS和CSS。 当需要进行恢复或缩放时,可以更快部署到另一台服务器,因为它只是一个混帐

用Mongoose制作validation器的正确方法是什么?

我有一个userSchema,首先带有自己的validation器的电子邮件,用户名和密码字段。 然后,我想添加更多的领域,如生物,位置性别和生日,也与他们自己的validation。 const userSchema=new Schema({ email: { type: String, required: true, unique: true, lowercase: true, validate: emailValidators}, username: { type: String, required: true, unique: true, lowercase: true, validate: usernameValidators}, password: { type: String, required: true,validate: passwordValidators}, bio: { type:String,required:false,default:null,validate:bioValidators}, location: {type:String,required:false, default:null}, gender: {type:String,required:false,default:null,validate:genderValidators}, birthday: { type:Date,required:false,default:null} }); 现在的问题是,当我想注册,它正在运行每个validation器,所以当然一​​个错误发生,因为在注册页面我甚至不要求生物,位置等。 我试着添加required:false但仍然没有工作,我没有find任何满意的答案 编辑 这是我如何创build一个新的用户 router.post('/register',(req,res)=>{ if (!req.body.email) […]

如何在本地查询区块链比特币

我下载了比特币核心钱包,下载了完整区块链的122GB文件到我的电脑。 我想在本地使用node.js进行查询。 任何想法我怎么能做到这一点?

在只有nodejs的环境中,在ES6 Module / Class中定义“真正的”私有方法,而不会泄漏任何信息

我知道,没有真正的私人方法INSIDE ES6类。 不过,我正在玩一下,发现了一些好东西 – 也许… 正如我所说,不可能不公开对象的属性。 但是我试图实现一些OOP编程,因为我把我的类分成单独的文件,然后导出这些类,如: class MyClass { constructor() { /** * Initialize stuff… */ } myMethod() { /** * Do public stuff… */ } } // expose class to environment. export default MyClass; 所以我可以导入类: import MyClass from './MyClass.js'; 当然myMethod可以从导入模块的其他文件访问。 Sinced我需要的variables和函数只能由我尝试过的类访问: // private variable outside of class scope but still accessible. let possiblePrivateVariable […]

Autobahn.JS掉线

我有一个Crossbar.js实现,在客户端(网站)和服务器(Node.js)之间通过Crossbar websocket服务器发送数据。 双方都使用Autobahn.JS连接到Crossbar服务器。 连接工作正常,但似乎客户端和服务器断断续续,随机时刻重新连接。 这大约每两分钟发生一次。 我也看到,双方的连接并没有同时发生。 这让我觉得问题在于我在双方使用的Autobahn实现(对于客户端和服务器来说大致相同)。 下面是我用来从Node.js连接到Crossbar服务器的方法。 浏览器的版本几乎完全相同。 我只改变了订阅,并改变了const并letvariablesvar 。 start(connectionConfig) { const self = this; self.host = connectionConfig.host; self.realm = connectionConfig.realm; self.channelPrefix = connectionConfig.channelPrefix; try { // Start an Autobahn websocket connection self.connection = new autobahn.Connection({"url": self.host, "realm": self.realm}); self.connection.onopen = function(session) { // Save session in class self.session = session; // Listen […]

与pg-promise的嵌套查询

我需要使用pg-promise进行查询,使用结果做出3个其他查询,但执行时出现这个错误: 未处理的拒绝types错误:方法'批'需要一个值的数组。 在C:\ apps \ pfc \ node_modules \ spex \ lib \ ext \ batch.js:149:26 at batch(C:\ apps \ pfc \ node_modules \ spex \ lib \ ext \ batch.js:61:26) Task.batch(C:\ apps \ pfc \ node_modules \ pg-promise \ lib \ task.js:120:39)………….. 这是我的代码: db.task(t => { return t.one('select gid, idgrupo from orden where gid […]

我是否应该将所有子包保存在package.json中的单个版本中?

我的项目使用的第三方库已经将其function分割为多个导入的包,以便项目可以安装它所需的东西。 在package.json中,不同的子包有几个条目,比如… "dependencies": { "@lib/dogs": "^1.0.3", "@lib/cats": "^1.0.3", "@lib/iguanas": "^1.0.3" …lots more of the same… } 如果其中一个子包通过semver-range-picking安装不同的版本号,而另一个开发人员通过在一个子包上递增版本来解决问题,我不想花时间考虑兼容性问题。 如果子包版本不同步,我怀疑存在一些bug的风险,即使包维护者的意图是尊重破坏版本变化的含义。 只是默认情况下,所有的子软件包都在相同的版本上似乎更简单。 我应该尝试执行(或者至less是提升)子包具有相同的版本吗?

在AWS Lambda中实例化AWS Helper类时是否需要指定区域?

如果我想从AWS Lambda调用AWS SES,那么在实例化AWS Helper类时通常会写下列内容: var ses = new aws.SES({apiVersion: '2010-12-01', region: 'eu-west-1'}); 我想知道,我是否真的需要指定AWS区域? 或者AWS SES帮助程序类将在运行AWS Lambda函数的区域中运行。 这里最好的做法是什么? 如果我忽略这个,可能会遇到问题吗?

“ejs.render”正在呼叫下一个路线

当我在http:// localhost / client中input时,显示404。 app.get('/client', function(req, res) { … ejs.render('any template', {}); … res.end(); }); app.get('*', function(req, res) { console.log('404'); … }); 但如果我删除“ejs.render”并把res.end('任何html')的作品。 我如何使用“ejs.render”而不是调用404? 谢谢。 这是一个错误。