我想在Node.js中更新表单数据,但是每当我运行这个代码,它将所有的值设置为null

app.put('/edit/:id', function(req, res) { //new actor data var actor = { 'name': req.body.name, 'dob': req.body.dob, 'photo': req.file, 'bio' : req.body.bio }; //updating actor Actor.findOneAndUpdate({ _id:req.params.id }, { $set: actor }, { new: true }, function(err, data) { if (err) { res.send({ status: false, error: err }); } else { res.send({ status: true, data: data }); […]

这是正常的bluebird / node.js / expresserror handling?

所以,我做了这个愚蠢的错字,花了我相当多的时间来find它,因为我总是从执行mongoose查询中得到一个空的错误。 我重新创build了一个更通用的行为。 var express = require('express'); var router = express.Router(); var Promise = require('Bluebird'); router.patch('/test', function (req, res, next){ var testPromise = new Promise(function (resolve, reject) { resolve(); }) .then(function(result){ if(thisIsAnExampleTypo){} res.status(200).json({ message: 'this will no be executed because of the typo', object: result }); }) .catch(function(err){ //console.log(err); return res.status(500).json({ title: 'This will execute because […]

离子生成android:没有在Iononic 2生成的APK文件

我刚刚在我的离子2项目上执行了命令“ionic build android”,并且成功地完成了它。 但是没有生成APK文件。 我应该做些什么? 提前致谢。 我使用节点v6.11.2,Ionic CLI 3.7.0,cordova 7.0.1。

Nuxt.js与护照失去req.user

我正在努力使用Nuxt.js和Passport.js Node.js应用程序。 我用vuexlogin并设置用户数据。 行动: nuxtServerInit ({ commit }, { req }) { if (req.session && req.session.authUser) { commit('SET_USER', req.session.authUser) } } 突变: SET_USER: function (state, user) { state.authUser = user } 它工作正常,但是当我试图访问页面,只能通过loged用户访问出现问题。 axios.get('http://localhost:3000/api/articles/add') router.get('/api/articles/add', ensureAuthenticated, (req, res) => { res.send({ title: 'Add Article' }) }) function ensureAuthenticated (req, res, next) { if (req.isAuthenticated()) { return […]

NPM:原生反应的同伴依赖

我试图在我的MacBook上创build我的第一个反应原生应用程序: $ npm install -g react-native-cli 在我的package.json中有 { "dependencies": { "react": "~15.4.0-rc.4", "react-native": "0.41.0", "react-native-image-carousel": "^0.3.2", "react-native-image-picker": "^0.25.7", "react-native-local-mongodb": "^1.8.2" } } 与npm install我得到的消息 npm WARN react-native-image-carousel@0.3.2 requires a peer of react-native@^0.40.0 but none was installed. npm WARN react-swipeable-views-native@0.10.5 requires a peer of react-native@^0.39.0 but none was installed. 我需要做什么?

node.js修改文件数据stream?

我需要修改一个大的数据文件到另一个目的地。 fs.readFile和fs.writeFile非常慢。 我需要逐行阅读,修改并写入新文件。 我发现这样的事情: fs.stat(sourceFile, function(err, stat){ var filesize = stat.size; var readStream = fs.createReadStream(sourceFile); // HERE I want do some modifications with bytes readStream.pipe(fs.createWriteStream(destFile)); }) 但如何进行修改? 我试图用data事件获取数据 readStream.on('data', function(buffer){ var str = strToBytes(buffer); str.replace('hello', ''); // How to write ??? }); 但不知道如何写入文件:

使用replaceOne时,节点upsertedId为null

我使用replaceOne作为便捷方法更新文档或创build一个文档,如果它不存在。 问题是,在创build的情况下,我没有得到upsertedId 。 但是我需要创build的文档。 的package.json "mongodb": "^2.2.31" MongoDb服务器版本是3.4.6 this.collection.replaceOne(filter,item,{upsert:true,w:1})返回 { modifiedCount: 0, matchedCount: 0, result: { "n": 1, "nModified": 0, "upserted": [ { "index": 0, "_id": null } ], "ok": 1 }, upsertedCount: 1 upsertedId: { "index": 0, "_id": null } } 在数据库中,upsertedObject也是使用null _id创build的

在Github Api中closurescertificatevalidation

我正在使用这个github api 。 var github = new GitHubApi({ // optional debug: true, protocol: "http", host: "github.my-GHE-enabled-company.com", // should be api.github.com for GitHub pathPrefix: "/api/v3", // for some GHEs; none for GitHub headers: { "user-agent": "My-Cool-GitHub-App" // GitHub is happy with a unique user agent }, Promise: require('bluebird'), followRedirects: false, // default: true; there's currently an […]

node.js – 如何caching使用服务工作者的handlebars.js

我想问一下服务人员。 我做了一个Web应用程序,并试图实现服务人员。 我为我的视图布局使用.hbs,当我caching静态文件时,我无法caching.hbs,.css和.js文件。 这是我如何保存我的文件: public/ css/ style.css js/ app.js manifest.json service-worker.js views/ home.hbs partial/ header.hbs 当我部署我的应用程序时,它无法cachinghome.hbs,style.css和我的app.js文件; 我无法离线访问我的网页。 我该怎么办才能解决这个问题? 这是我的app.js: if ('serviceWorker' in navigator) { navigator.serviceWorker .register('./service-worker.js', { scope: './service-worker.js' }) .then(function(registration) { console.log("Service Worker Registered"); }) .catch(function(err) { console.log("Service Worker Failed to Register", err); }) } var get = function(url) { return new Promise(function(resolve, reject) […]

任何人都可以解释两个用户在mongodb3.4.5中的区别

//the first user { "_id" : "admin.guguji55", "user" : "guguji55", "db" : "admin", "roles" : [ { "role" : "readWrite", "db" : "test" } ] } //the second user { "_id" : "test.guguji66", "user" : "guguji66", "db" : "test", "roles" : [ { "role" : "readWrite", "db" : "test" } ] } 我创build了两个用户,'guguji55'不能连接我的testing数据库,但'guguji66'可以做到这一点。我不知道为什么。我的nodejs连接代码如下: MongoClient.connect('mongodb://guguji66:du****kuan****@localhost:27017/test', function(err, […]