如何以angular度显示图像(图像在服务器端上传文件夹和angularjs在不同的服务器上工作)?

我使用multer,node.js,mongodb上传图像。 我上载的文件夹中的图像,我存储在MongoDB中的path。 这是我的文件夹结构 服务器正在运行 http://localhost:3000/images/590051dcc90cf702e452b9c1 基于文件ID我正在回顾文件 // To get the single image/File using id from the MongoDB app.get('/images/:id', function(req, res) { //calling the function from index.js class using routes object.. routes.getImageById(req.params.id, function(err, genres) { if (err) { throw err; } //res.download(genres.path); res.send(genres) }); }); 我得到了这样的回应 {"_id":"590051dcc90cf702e452b9c1","path":"uploads\login.jpg","name":"asdf","email":"asdf@gmail.com","originalname":"login.jpg","__v":0} 我正在发送上述响应angular度和andriod应用程序。 现在我想以angular度显示这个图像。 angular度服务器工作在不同的服务器节点服务器在不同的服务器上工作 我就这样 </head><body> <body ng-controller="RegisterCtrl" ng-app="myApp"> <div […]

快速validation与mongoose

我正在开发我自己的网站使用(angularjs,bootstrap)前端(节点,快递)为后端(MongoDB,mongoose层)的数据库。 我有一个registry格,在这个表格中,我想检查一下,当有人尝试创build新的帐户时,电子邮件还没有被采取,所以我希望我的注册API检查提交的电子邮件是否已经被采取过。 我现在使用这个validation器https://github.com/ctavan/express-validator#validation-by-schema ,这是我的代码: var vadlidateRegUser= function (req,res,next) { req.checkQuery('UserName','Username must contain letters and numbers only').isAlphanumeric().notEmpty(); req.checkQuery('Email','Email should have a valid syntax eg: example@example.com') .isEmail().notEmpty(); var error = req.validationErrors(); if(!error){ next(); }else { res.json({success:false, message:error}); } } 现在我想检查一下validation器,如果电子邮件是唯一的,就像这样: req.checkQuery('Email','Email should have a valid syntax eg: example@example.com') .isEmail().isUnique(Model Name); 有什么build议么 ?

如何在客户端获取JSON对象

我目前正试图发送一个JSON对象从服务器到客户端,但我不知道如果我正确访问它。 app.post('/url', function(request, response){ …. var result = fuse.search(); response.json(result); // results should be sent back as a response }) $.post("/url", options, function(response, request) { var json = response.json; )

哪个版本的Javascript

注:我知道这可能是一个简单而基本的问题,但是几年前我刚刚开始学习Javascript,当时所有这些变化都开始发生,而且似乎我学到了旧版本。 我与Javascript混淆。 我试图实现一个基本的MEAN堆栈。 我在服务器端使用es6 Javascript与Nodejs(6.x)。 然后对于客户端来说,我在es5 Javascript中使用了Angular 1.5,但它似乎没有工作。 可以在服务器端混合使用es6,在客户端使用es5或者是全部或全部都是…在服务器/客户端上都是es6,反之亦然? 更新感谢所有的信息。 我一直在寻找ES6(ES2015),这似乎并不困难,我甚至写了一些代码成功。 不过,我刚刚得到了angular1的处理,然后看起来像angular1.6和上来,是完全不同的。 Angular 1有相当的学习曲线,将Angular 1的代码更新到1.6或更高版本会有多难? 是ES3中新的Angular? 所有在ES6中编写的前端JS需要一个转储程序,或者浏览器现在可以处理ES6吗?

如何存储与sinon的asynchronous数据库调用

我想unit testing这个类的getAll方法: module.exports = class BookController { static async getAll() { return await Book.query() .eager('reviews'); } }; 本书是一个异议模型。 我想testing它是我想用我自己的数据伪造Book.query().eager()的响应,因为我永远不能validation数据库中的内容。 为了成为一个真正的unit testing,我应该只是testingBook.query()方法被调用? 或者我应该testing返回的数据,因为这是getAll()方法的契约? 我真的不确定我应该如何把这一点弄糟。

NodeJS / MongoDB – 字段只添加一次?

我正在学习与Node(Express / Mongoose)和MongoDB的React,一切似乎现在按预期工作,但我有这个大问题: var userSchema = new mongoose.Schema({ login: { type: String, required: true, unique: true }, password: { type: String, required: true } }) app.post('/registerUser', function (req, res) { res.send(req.body) db.on('error', console.error.bind(console, 'connection error:')) // save user using model var user = new UserModel(req.body) user.save() } 每次我POSTlogin和密码,它只被保存一次,然后结束。 所以例如,如果我发送POST三次: login=admin&password=admin login=admin2&password=admin2 login=admin3&password=admin3 db.users.count()显示1 , 只有第一个POST […]

弃用警告:未处理的承诺拒绝已被弃用

我得到了这个错误在我的代码,我不知道如何解决它? DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 我的代码到目前为止: router.post('/users/*', (req, res) => { User.create(new User({ email: req.body.identity.user_email, authUserId: req.body.identity.user_id })) res.json(console.log("User Created")) }) router.get('/users/:id', (req, res, next) => { User.findOne({authUserId: req.params.id}, (err, userr) => { if(err) […]

jQuery和Express – 成功和错误混合起来

这是一个基本的问题,但它一直在唠叨我一会儿,到目前为止我找不到任何匹配的问题。 所以,如果太简单或重复,我们表示歉意。 我有一个API路由(基于Express),我打电话给这条路线使用jQuery AJAX调用。 这是一个简单的存根来演示设置 $.ajax({ url: "http://localhost:3000/admin/items/" + itemId, type: "POST", dataType: "json", data: itemData, contentType: "application/json", success: function(result){alert(result);}, error: function(xhr, ajaxOptions, thrownError){ alert("Could not update item details. Please try again later. Error: " + xhr.statusText); } }); 从服务器,我确认返回的状态码是200,这是执行: collection.update({ _id : mongo.ObjectID(req.params.id) }, req.body, function(err, result) { if(err){ console.log("Error is: " + err); […]

Mongoose:如何在控制台中显示一个对象types混合的内容?

用以下数据 : lines: [{ line: [12, 'Joe'] }, { line: [14, 'John'] }, { line: [6, 'Walter'] }, { line: [3, 'William'] }, { line: [18, 'Bill'] }, { line: [22, 'Albert'] }] 和模型 const Schema = mongoose.Schema; const Line = new Schema({ line: [Schema.Types.Mixed] }); const TableSchema = new mongoose.Schema({ lines: [Line] }); 当我保存然后在控制台显示集合我得到: […]

从nodejs的get方法中获取错误的参数

我想发送获取方法请求,并希望在URL中传递值。 像我的API看起来像 app.get('/api/getlocation/:customerName', customer.getlocation); 为了这个电话我写邮递员 localhost:8080/api/getlocation/:customerName=kumbhani 为了testing var customerName = req.params.customerName; console.log('name', customerName); // =kumbhani 它返回名称= sign – 我只需要kumbhani