我如何在js中像Excel中的圆形函数一样以负的精度舍入一个数字

我正在尝试从8904000到8900000的值。有没有什么可能的方法来改变这个使用Math.round。 在MS Excel中的例子 =round(8904000,-5); ANS: 8900000 我尝试了下面的代码,但Math.round不采取第二个参数 Math.round(8904000,-5); ANS: 8904000 总之我想把这个数字凑到最接近的100,000个数字 所以5300 * 56 * 30 = 8904000变成8900000

Concat将数据stream式传输到单个文件或string,同时使用Node提取zip文件

我正在使用yauzl节点模块。 我从Zip文件中提取XML文件。 读取条目时,在readSteam.on('data')callback函数中,我将entry.filename及其内容logging为string。 但是,有些文件被分解成多个文件。 这些部分共享相同的fileName 。 每个部分都包含部分文件内容。 let options = { lazyEntries: true } yauzl.open(params.pathToZip, options, function(err, zipfile) { if(err) throw err zipfile.readEntry() zipfile.on("error", function(err) { throw err }) zipfile.on("entry", function(entry) { if (/\/$/.exec(entry)) return false zipfile.openReadStream(entry, options, (err, readStream) => { if (err) throw err readStream.on('data', data => { console.log(entry.fileName) console.log(data.toString()) }) }) zipfile.readEntry() […]

Express / Node.js错误:参考错误:Res未定义

我正在尝试为我的团队应用程序创build一个基本的CRUD应用程序,但是我遇到了一些基本问题。 为了构build我的crud应用程序,我正在使用node.js,express和mongodb。 我在使用部分代码时遇到了一些麻烦,我想知道是否可以指引我朝着正确的方向发展。 (这是一个冗长的问题,我尽我所能来格式化,以免它在阅读的时候灼伤你的眼睛…对不起,如果很难读) 上下文:供参考我使用这个: https://zellwk.com/blog/crud-express-mongodb/, currently on "Showing quotes to users" 我的问题:每次我初始化res.render(视图,本地人)我的节点服务器崩溃。 这是我得到的错误。 res.render(view, locals) ReferenceError: res is not defined at Object.<anonymous> (C:\Users\hcqph\xx\xcxx\server.js:35:1) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:393:7) at startup (bootstrap_node.js:150:9) at bootstrap_node.js:508:3 我的代码:这是我到目前为止server.js。 现在,每当我尝试导入我的index.ejs文件,每当我尝试导入下面的行时,我得到一个错误: res.render(views, locals) 这是我的代码为server.js […]

在查询中join限制和偏移不正确的位置

我在nodeJs中使用了sequelize,我有这样的代码: Time_Sheet_Details.findAll({ include: [ { model: timesheetNotesSubcon, required: false, attributes:["note","file_name", "id", "working_hrs", "timestamp", "has_screenshot", "notes_category"] }, { model: Timesheet, attributes:["id","leads_id","userid"], include:[ { model: Lead_Info, attributes:["id","fname","lname","email","hiring_coordinator_id","status"], where: { hiring_coordinator_id : 326}, include:[{ model: adminInfoSchema, required: false, attributes:["admin_id","admin_fname", "admin_lname", "admin_email", "signature_contact_nos", "signature_company"], }] }, {model:Personal_Info,attributes:["userid","fname","lname","email"]} ], }], where: { reference_date: filters.reference_date }, order:[ ["id","DESC"] ], offset:((1-1)*30), limit […]

有没有办法强制npm安装从Intranet位置的所有依赖项

假设我的内部网中有一个目录,其中包含一个node_modules文件夹,其中包含所有依赖关系,这是我的Web项目工作所需要的。 据我所知,我可以input类似的东西(在我的项目的根文件夹在terminal): npm i "\\RepoComp\Repo\node_modules\bootstrap" 所以,它会将bootstrap包安装到我的项目中。 这是相当不错的,但我不想安装我的package.json手动列出的所有包,我只想input: npm i <path-to-intranet-repo> 我期望npm从这个内联网位置收集所有的依赖关系。 我怎样才能做到这一点? PS:其实,我试图实现的是将所有的依赖关系放在内部networking的远程文件夹中,所以我的团队中的所有开发人员都可以从那里访问所需的软件包,而无需连接互联网。 可能吗? 但是,正如我从npm-debug.log中发现的,它试图连接到registry.npmjs.org,同时试图通过npm –prefix "\\RepoComp\Repo\node_modules\" install命令来安装软件包。

使用Sequelize.jsjoin特定的列

我正在尝试使用Sequelize.js在特定列上join一些表格。 到目前为止,我的代码是这样的: table_1.findall({ include: [{ model: table_2 attributes: ['id', 'another_id'] include: [{ model: table_3 required: true attributes: ['time'] }] }] }) 每个表的主键都是“id”。 这似乎等同于下面的SQL(为了简洁起见,我显示了SELECT *,因为这不是这个问题的焦点): SELECT * FROM table_1 as t1 LEFT OUTER JOIN table_2 as t2 ON t1.id = t2.t1_id INNER JOIN table_3 as t3 ON t2.id = t3.t2_id 我想有这样的东西: SELECT * FROM table_1 as […]

我可以复制“node_modules”目录到其他机器,而不必每次都运行“npm install”吗?

两台Linux机器。 两者都是CentOS x64,但版本不同。 假设我在机器#1上运行npm install ,将包括node_modules目录在内的整个应用程序复制到机器#2并在那里运行。 是否支持? 或者,总是build议在每台机器上运行npm install ? 我成功地在Centos 6 x64机器上执行npm install ,将包括node_modules的应用程序复制到Centos 7 x64机器上。 应用程序似乎运行良好。 即使它对我有用,这样做通常是安全的吗?

MongoError:多更新只适用于$运算符,而在node.js中使用批量查找和更新

为什么会出错 MongoError:多更新只适用于$操作符 同时使用bulk find and update来更新多个文件。 试过: var bulk = db.collection('users').initializeUnorderedBulkOp(); var emails = ['a@gmail.com', 'b@gmail.com', 'c@gmail.com','d@gmail.com']; var allStatus = ['s1', 's2', 's3', '']; for (var i =0; i< allStatus.length; i++) { var query = { email: emails[i], status: { '$ne': allStatus[i] } }; var updateField = {}; if(allStatus[i]) { updateField = { $set: {status: […]

只运行一次函数

我怎样才能调用和使用这个函数只是为了一个时间,然后再杀死函数? 调用函数: else if (msg.text == ["📠contact us📠"]) { const opts = { reply_to_message_id: msg.message_id, reply_markup: JSON.stringify({ keyboard: arrangeKeyboard(locale.keyboards[msg.text].childs, 2, msg), resize_keyboard: true, one_time_keyboard: true }) }; bot.sendMessage(msg.chat.id, "Please Write your Messages:", opts); getmessage1(); } 这是我的function,我不想在一个循环运行,我需要发送消息和杀死function。 var getmessage = async () => { // Listen for any kind of message. There are different kinds of […]

如何保存一个MongoDB查询,然后运行它?

我在应用程序A中加载了一个MongoDB查询。 例如: const query = { country: new ObjectId(""), age: { $gte: 25 } } // save contents of 'query' …我想将其保存在DB中,并使应用程序B运行它: // const query = read object from the database db.collection('foo').find(query).toArray()… 我现在想把它保存在mongo中,并在稍后的时间检索它运行。 但MongoDB不允许我用$gte值保存文档。 我已经试过JSON.stringify(query) ,将结果string保存在数据库(好!),然后parsing它在另一边。 然后,面对ObjectId像这样string化的问题: { "class" : "org.bson.types.ObjectId", "counter" : 9053980.0, "date" : "2015-04-01T19:24:39Z", "machineIdentifier" : 14987412.0, "processIdentifier" : 29601.0, "time" : 1427916279000.0, […]