node.js

Can't run npm install

99封情书 提交于 2021-02-11 08:01:09
问题 In here it says to run npm install , but I get this error when I run sudo npm install . sudo npm install npm WARN enoent ENOENT: no such file or directory, open '/var/www/html/mg/package.json' npm WARN mg No description npm WARN mg No repository field. npm WARN mg No README data npm WARN mg No license field. without sudo: npm install npm WARN enoent ENOENT: no such file or directory, open '/var/www/html/mg/package.json' npm WARN mg No description npm WARN mg No repository field. npm WARN mg

Send a POST request on the server with Express.js

二次信任 提交于 2021-02-11 07:44:18
问题 I'm running into a small issue with something I thought was possible. I want to have two express routes, one GET route /post-data and one POST route /post-recieve . The code would look something like this: app.get('/post-data', (req, res, next) => { //set url to '/post-recieve' and set body / headers }) app.post('/post-recieve', (req, res, next) => { return res.json(res.body) }) Now, when you visit /post-data you should be instantly redirected to /post-recieve except if you look in the

Async db calls using recursion

≯℡__Kan透↙ 提交于 2021-02-11 07:33:27
问题 I have a need to recursively descend a linked list database tree item 1-> item 2 -> item 3 -> item 4 -> item 5 -> item 6 -> item 7 -> item 8 my pseudo code is var getItems = function(itemid) { db.getitem(itemid, function(item) { item.items.forEach(function(subitem) { getItems(subitem.id) }) }) getItems(1) however, db.getItem is an asynchronous function I would like to return a JS object in the same structure as the diagram to the top-level caller what is the best way of achieving this ? I don

Calling external api endpoints when working with node and ejs and geting the details for your users

丶灬走出姿态 提交于 2021-02-11 07:28:09
问题 i have a signup and login form,am using ejs to render as view, i have been given some api endpoint to call, and i have added them to their ejs form action views when i fill in the user details in my ejs view form i get this response. i get this when am trying to register a user { "status": 200, "message": "Account created successfully.", "data": { "name": "name of user", "email": "user email", "password": "$2b$10$0IPgBNCJhjjkasdkGb2y0CviOuxRe/bAfhFqFDqrofMaCz5f0SMtwkgBxIzm" } } i get this

Calling external api endpoints when working with node and ejs and geting the details for your users

房东的猫 提交于 2021-02-11 07:27:30
问题 i have a signup and login form,am using ejs to render as view, i have been given some api endpoint to call, and i have added them to their ejs form action views when i fill in the user details in my ejs view form i get this response. i get this when am trying to register a user { "status": 200, "message": "Account created successfully.", "data": { "name": "name of user", "email": "user email", "password": "$2b$10$0IPgBNCJhjjkasdkGb2y0CviOuxRe/bAfhFqFDqrofMaCz5f0SMtwkgBxIzm" } } i get this

mongoose model, array of strings, array of objects structure

[亡魂溺海] 提交于 2021-02-11 07:24:43
问题 I am trying to design my database model and i dont have clue how to fit array of strings and array of objects into it. My current model is: const mongoose = require("mongoose"); const Schema = mongoose.Schema; const schema = new Schema({ email: { type: String, unique: true, required: true }, hash: { type: String, required: true }, createdDate: { type: Date, default: Date.now }, settings: { favorites: { /* ??? */ }, cart: { /* ??? */ }, states: { favorites: { type: Boolean, default: true },

MS Teams app manifest file Tenant restriction

断了今生、忘了曾经 提交于 2021-02-11 07:22:26
问题 I created the bot application and created the manifest file for it. I added it to the Microsoft teams and it is working fine. So if I use that manifest file with the other tenant account then also that app will be added and working. I don't want it to be like this. If the other tenant people tries to add the manifest it should not work or added. How to give tenant restriction in the manifest file? I am attaching my manifest file also. { "$schema": "https://developer.microsoft.com/en-us/json

find({}) returns an empty array mongoose

依然范特西╮ 提交于 2021-02-11 06:56:10
问题 Here is my code in model.js file: const mongoose = require("mongoose"); const con = require("./connection"); con(); const schoolNotices = mongoose.model("schoolNotices", { title:{ type: String }, date:{ type:String }, details:{ type:String } }); module.exports = schoolNotices; And I have imported this code into students.js file router.route("/notices") .get((req,res)=>{ schoolNotices.find({},(err,docs)=>{ if(err){ return console.log(err) } res.render("studentNotices",{title:"Notices",data

nodejs express url rewrite?

穿精又带淫゛_ 提交于 2021-02-11 06:55:54
问题 I am new to nodejs and just started learning it. I started with express. Everything's good but have a question not sure if this needs to be URL rewrite or URL redirect. views folder looks like below, (jade files) views - index - news - videos The first page definitely is index, url is localhost:3000. Now I want my news page to be the index page, so when I enter localhost:3000 or localhost:3000/news, I want always to see the news.jade content. but I don't want to duplicate news.jade to index

Mongoose join two collections and get only specific fields from the joined collection

人盡茶涼 提交于 2021-02-11 06:55:00
问题 I have a problem joining two collections in mongoose. I have two collections namely: student and exams. Student model: { fullname: { type: String, required: true }, email: { type: String, required: true }, } Exams model: { test: { type: String, required: false }, top10: [ type: { studentId: { type: String, required: true }, score: { type: Number, required: false }, } ] } Now, I want to join them two by studentId . The result should be: { "test": "Sample Test #1", "students": [ { "studentId":