node.js

Get diff between two tags with nodegit

故事扮演 提交于 2021-02-08 08:20:15
问题 How do I get the diff between two tags using nodegit? On the command line, I can see the diff between two tags, no problemo. Additionally, I can use nodegit to list the tags in my repo: const Git = require('nodegit') const path = require('path') Git.Repository.open(path.resolve(__dirname, '.git')) .then((repo) => { console.log('Opened repo ...') Git.Tag.list(repo).then((array) => { console.log('Tags:') console.log(array) }) }) However, I am not sure how to find the diff between two tags in

Read excel file with password protection from nodejs

偶尔善良 提交于 2021-02-08 08:19:23
问题 Have a task, to parse password protected excel-file. Is there any library to work with password protected files for nodejs? I have explored ExcelJS and Node-xlsx, but there are no info about password protected files... 回答1: Found lib for node js https://www.npmjs.com/package/xlsx-populate it working with password-protected excel files 来源: https://stackoverflow.com/questions/50333422/read-excel-file-with-password-protection-from-nodejs

Mongoose Compound Index Unique + Sparse

落花浮王杯 提交于 2021-02-08 08:16:44
问题 I want to create an index which ensures, that I don't have a duplicate serialNr within the combination of a manufacturer + art . But some items don't have a serialNr . These I don't want to check/index. Code mySchema.index({ serialNr: 1, art: 1 , manufacturer: 1, deleted: 1}, { unique: true, sparse: true) I tried it also with adding a partial Filter: partialFilterExpression: { serialNr: {$ne:null} } to the index options. Question How can I index it that inserting: [{art: 'a', manufacturer:'a'

Unable to exchange auth-code to get access-token using Microsoft identity platform in my node application

不羁的心 提交于 2021-02-08 08:16:22
问题 I am implementing OAuth2 using Microsoft identity platform. For this purpose, I registered my app to Azure Active Directory admin center and got an app-id and other app credentials. Redirect-url also mentioned as well. So first of all, I generated auth-url (code snippet is provided below) and got an auth-code to my redirect endpoint. when I try to exchange auth-code to get access-token, it throws as exception with statuscode 401 with error message "401 Unauthorized". I am using simple-oauth2

How to set character limits in content in ejs template

不羁岁月 提交于 2021-02-08 08:13:02
问题 I am fetching content from Mognodb in EJS template. I have description field which contains more then 500 characters, but I want to show only 50 Characters in my view. Can anyone tell me how to do it. 回答1: In the view you can use JavaScript String.prototype.substring(): <%= description.substring(0, 50) %> Within MongoDB you can use $substr to return a new field with the desired 50 characters: db.collectionName.aggregate([{ $project: { title: 1, shortDescription: { $substr: ["$description", 0,

How to set character limits in content in ejs template

╄→гoц情女王★ 提交于 2021-02-08 08:12:39
问题 I am fetching content from Mognodb in EJS template. I have description field which contains more then 500 characters, but I want to show only 50 Characters in my view. Can anyone tell me how to do it. 回答1: In the view you can use JavaScript String.prototype.substring(): <%= description.substring(0, 50) %> Within MongoDB you can use $substr to return a new field with the desired 50 characters: db.collectionName.aggregate([{ $project: { title: 1, shortDescription: { $substr: ["$description", 0,

Start and Stop Python Script from NodeJS?

大城市里の小女人 提交于 2021-02-08 08:01:51
问题 How can I start and stop a python script from a NodeJS server? I have seen the module "python-shell", but it doesn't provide a way to kill the script after running it. 回答1: Use child_process. Example from the doc: const { spawn } = require('child_process'); const child = spawn('python3', ['script.py']); child.on('close', (code, signal) => { console.log( `child process terminated due to receipt of signal ${signal}`); }); // Send SIGTERM to process child.kill('SIGTERM'); 来源: https:/

Function to return data from SQLite3 query in node.js

你离开我真会死。 提交于 2021-02-08 07:58:26
问题 I'm making a bot for Discord, and one of the features in this bot is a level system. I've decided to go from using JSON to store the data, to sqlite. I'm using sqlite3 in node.js and am trying to create a function to create / retrieve a player's data. My goal is to make this function return the data from the query, but I'm running my head into a brick wall trying to figure out what I'm doing wrong. I've read that I need to use callbacks sent to the query function, but that has not worked for

How to clone a Mongodb database with Mongoose

泪湿孤枕 提交于 2021-02-08 07:56:34
问题 Is there a way to clone a collection or entire Mongodb database (my databases only have one collection so both options are OK) with Mongoose? I saw that there is a possibility to execute raw Mongo commands with Mongoose. What command can I use to clone an entire collection or db from one db to another? Thanks in advance. 回答1: I had a hard time doing this I don't have any reference. However, this is how I did on my end. 1, I created another collection within the same db: mydb collections:

Improving MongoDB Text Search Performance

断了今生、忘了曾经 提交于 2021-02-08 07:50:39
问题 I'm looking for some advice about how improve Text Search performance with MongoDB 2.6. I am also using Mongoose. My mongoose schema has 'body: String' which contains a large chunk of XML. I ran ensureIndex which took a few minutes... db.models.ensureIndex({ body:"text"}) I want to search this text with a user defined string. Model.find({ $text: { $search: searchstr }},function(err,data){ }); While there are only a few thousand documents, the search will often time out ( 2 minutes+). How can