Tag: javascript

Sequelize.define不是一个函数

我最近开始玩node.js,所以我是新来的。 在node.js控制台中出现以下错误无法上传图片,显然是因为我的评分,请点击链接 以下是我的代码。 var Sequelize = require('sequelize'); const dbConfig = new Sequelize('Mike_Test', 'sa', '[DBPASSWORD]', { host:'179.27.69.555', dialect: 'mssql', port: 1433, pool: { max: 5, min: 0, idle: 10000 }, }); //Model Schhema function createDB(){ var Customer2 = Sequelize.define('Customers2', { Name: { Name: Sequelize.STRING, allowNull: false }, Email: { Email: Sequelize.STRING, allowNull: false }, Phone: { […]

JavaScript-“找不到图片”,除非我刷新页面

我正在开发简单的聊天应用程序,使用node.js服务器和HTML , CSS , JavaScript的客户端,每个注册用户我生成一个gravatar取决于他的电子邮件,为匿名用户(没有电子邮件)我设置一个默认用户image.I将用户的详细信息保存在服务器的一个数组中,所以当用户login时,他们会看到聊天消息,并在他们旁边看到用户图像或他的头像。 问题是,实时更新消息显示,但图像不是除非我刷新页面。 我确定保存在服务器中的图像的URL是合法的,因为即使在刷新页面时也不能显示它们。 我得到follwing错误: GET / client / undefined“错误(404):”未find“ 编辑 server.js: function addMessage(message) { var m = (message); if (m.email === "" || m.email===undefined) { gravatar = "/client/images/user.png"; } else { var userimg= globalVar.usersList.findIndex(function (element) { return element.email === m.email; }); gravatar=globalVar.usersList[userimg].gravatar; } var newMessage = { name: m.name, email: m.email, […]

循环通过条形码canvas创build缓冲区并写入文件

为了解决这个问题,我正在用一些基本的代码来解决这个问题。 这只是testing一个更大的项目的一些function,我试图find一种方法来接受一个数组填充canvas对象的函数。 然后我也需要循环这些canvas对象,并创build一个缓冲区来写入一个文件。 由于某种原因,当我运行这个如何,我认为我应该asynchronous,它只能保存最后的条码多次。 对我来说,我的saveBarcode()函数似乎是一个错误,其中toBuffer和writeFile函数运行asynchronous,但是它们在toBuffer和writeFile函数中失去了循环im的迭代值。 我似乎找不到一个更好的方式来保存所有这些条形码canvas'文件。 任何input将不胜感激! 如果你需要更多的细节,我会尽我所能回答一切。 这是整个代码: const JsBarcode = require("jsbarcode"); const Canvas = require("canvas"); const fs = require("fs"); //makeid creates a Random 12 Digit # to represent the barcode number, It returns an Array of barcodes based on the amount inputted let makeid = (amount) => { let barcodeArray = []; let […]

为多个关系表添加js orm播种器

我将这样sequelize种子初始数据加载邮政。我可以通过创buildseedfile.js.能够做到多表,但我无法处理表之间的关系自动。 // user_seeds.js up: function (queryInterface, Sequelize) { return queryInterface.bulkInsert(table, [{ uid: 1, //primary key autogenerated name: 'John doe', email: 'john@doe.com', created_at, updated_at }], {}); // roles_seeds.js up: function (queryInterface, Sequelize) { return queryInterface.bulkInsert(table, [{ uid: 1, //this should be comes from user table to this filed automatically after the creation of first record in […]

准备好的语句不能在节点js中用mssql执行

在运行代码之后,我得到的只是控制台日志“完成”,没有更新数据库。 我究竟做错了什么? var pool = new sql.ConnectionPool(config); var ps = new sql.PreparedStatement(pool); ps.input('code', sql.VarChar); ps.input('hex', sql.VarChar); ps.prepare("UPDATE tHE_SetItem SET acPicture = CONVERT(varbinary(max), @hex, 2) WHERE acIdent = @code;", function(err) { async.mapSeries(hexes, function(pair, next) { ps.execute({code: pair.code, hex: pair.hex}, next); }, function(err) { ps.unprepare(function(err) { console.log("Done!"); }); }); });

使用webpack目标节点从node_modules导入css

我目前正在build立一个服务器端渲染反应的应用程序。 我正在使用一些与CSS文件来的库。 当我尝试像这样导入它们时: import 'leaflet/dist/leaflet.css'; 我在我的server.js得到以下错误: /my/app/path/node_modules/leaflet/dist/leaflet.css:3 .leaflet-pane, ^ SyntaxError: Unexpected token . at createScript (vm.js:74:10) at Object.runInThisContext (vm.js:116:10) at Module._compile (module.js:533:28) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:503:32) at tryModuleLoad (module.js:466:12) at Function.Module._load (module.js:458:3) at Module.require (module.js:513:17) at require (internal/module.js:11:18) at Object.__webpack_exports__.a (/my/app/path/server.js:725:18) 导入 import '../../node_modules/leaflet/dist/leaflet.css'; 作品。 有没有办法configurationwebpack,我可以正常导入这些css文件? 这里是server.js的webpackconfiguration: const nodeExternals = require('webpack-node-externals'); const postcssImport […]

Node JS MY SQL使用promisepipe理事务

我想在一个事务中将对象保存到数据库中。 对象有两个子对象和一个数组列表对象,数组列表中的每个对象都有自己的数组列表: { "person": { "id": null, "personal_no": "555555555555555555" }, "reservation": { "id": null, "personal_no": null, "status_id": null, "reservationDetail": [ { "id": null, "status_id": null, "room_id": 44, "start_date": "2017-08-09T18:04:26.938Z", "end_date": "2017-08-09T18:04:26.938Z", "category_id": 64, "reservationPerson": [ { "reservation_id": "123", "person_id": "5555555555555555551" }, { "reservation_id": "123", "person_id": "5555555555555555552" } ], "reservationService": [ { "reservation_id": "123", "person_id": "5555555555555555553" […]

如何同步一系列的承诺?

我有一个promise对象数组,它们必须按照它们在数组中列出的顺序来parsing,也就是说,我们不能尝试parsing一个元素,直到前一个元素已经被parsing(方法all([…]) )。 如果一个元素被拒绝,我需要链条立即拒绝,而不是试图解决下面的元素。 我怎样才能实现这个,或者是否有这样的sequence模式的现有实现? function sequence(arr) { return new Promise(function (resolve, reject) { // try resolving all elements in 'arr', // but strictly one after another; }); } 编辑 最初的答案build议我们只能sequence这些数组元素的结果,而不是它们的执行,因为它是在这个例子中预定义的。 但是,那么如何以避免提前执行的方式生成一系列的promise? 这是一个修改的例子: function sequence(nextPromise) { // while nextPromise() creates and returns another promise, // continue resolving it; } 我不想把它作为一个单独的问题,因为我相信这是同一个问题的一部分。 解 下面的一些答案和后面的讨论有点不对劲,但最终的解决scheme正是我所期待的,它是在spex库中作为方法序列实现的 。 该方法可以迭代一系列dynamic的长度,并根据应用程序的业务逻辑的需要创buildpromise。 后来我把它变成了一个供大家使用的共享库。

nodejs mongoDB findOneAndUpdate(); 即使在数据库更新后也会返回true

我正在研究Ionic-1 + nodejs +angular度应用程序。 即使第一次调用更新数据库,我的mongoDb findOneAndUpdate()函数在每次调用时都会返回true。 的NodeJS: app.post('/booking', function (req, res) { var collection = req.db.get('restaurant'); var id = req.body.id; var status = req.body.status; collection.findOneAndUpdate({status: status, id: id},{$set:{status:"booked"}}, function (e, doc) { console.log(id, status); if (e) { console.log(e); } else if(!doc) { res.send(false); } else { res.send(true); } }); }); controller.js $scope.bookMe = function(id){ var […]

opencv – TypeError:无法读取未定义的属性“长度”

我最近安装了opencv并执行了npm install 。 这样做后,我给了一些示例代码,看看它是否工作,但它不工作,我不知道为什么。 也许我安装不正确,我是这个新手。 这里是代码: cv.readImage("./examples/files/mona.png", function(err, im){ im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){ for (var i=0;i<faces.length; i++){ var x = faces[i] im.ellipse(xx + x.width/2, xy + x.height/2, x.width/2, x.height/2); } im.save('./out.jpg'); }); })