express

Why does Express.js populate method fail in this application?

吃可爱长大的小学妹 提交于 2020-04-18 03:56:02
问题 I am working on a blogging application (click the link to see the GitHub repo) with Express, EJS and MongoDB. I have Posts and Post Categories , each in its own collection. The Categories Schema: const mongoose = require('mongoose'); const categorySchema = new mongoose.Schema({ cat_name: { type: String, required: true }, updated_at: { type: Date, default: Date.now() }, created_at: { type: Date, default: Date.now() } }); module.exports = mongoose.model('Category', categorySchema); The Posts

Express.js application bug causes Route.post() requires a callback function but got a [object Undefined] error

≡放荡痞女 提交于 2020-04-18 03:54:57
问题 I am working on a blogging application (click the link to see the GitHub repo) with Express, EJS and MongoDB. I am trying to introduce an add post image feature with Multer. Being quite new to Express, I run into trouble. In utils\imageupload.js I have added: const multer = require("multer"); const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, './uploads/images') }, filename: function (req, file, cb) { cb(null, file.fieldname + '-' + Date.now() + '.png') } })

Mongoose unique validation not working. Duplicate entries getting saved

♀尐吖头ヾ 提交于 2020-04-17 22:57:53
问题 I am working on a NodeJS application where, express is the framework & MongoDB is the database. I am using mongoose plugin for it. I have a parent model. I have added unique: true to field " mobile ". But whenever I add same mobile number, uniqueness validation fails. Nothing happens rather duplicate document gets saved. The required validation works fine but unique validation does not work only in this particular model. Below is the model parentModel.js var mongoose = require('mongoose');

Mongoose unique validation not working. Duplicate entries getting saved

浪尽此生 提交于 2020-04-17 22:57:45
问题 I am working on a NodeJS application where, express is the framework & MongoDB is the database. I am using mongoose plugin for it. I have a parent model. I have added unique: true to field " mobile ". But whenever I add same mobile number, uniqueness validation fails. Nothing happens rather duplicate document gets saved. The required validation works fine but unique validation does not work only in this particular model. Below is the model parentModel.js var mongoose = require('mongoose');

How do I query a specific Post by slug property value in mongoose instead of id?

瘦欲@ 提交于 2020-04-17 22:53:14
问题 I know how to query a specific post by id. However I want to use the slug property of the post instead of its id to to query it. How do I do so ? //Instead of req.params.id, we have req.params.slug instead //How do get the post in this case if the Post database model has a slug property. //We have the req.params.slug //This is what needs to be changed const post = await Post.findById(req.params.id, (error, post) => { console.log(error, post) }).populate('author') Here is the Post model: const

Running cron job at only specific date and time

拟墨画扇 提交于 2020-04-17 22:50:44
问题 In our express js application have a feature in admin module that he can send mail to users at specific dates (he can able to select a specific date and time). Say if the date and time is 2018-02-22@12.00 we need to run the email code at that time. I think this package will full fill our needs https://www.npmjs.com/package/node-schedule, Here is their documentation * * * * * * ┬ ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ │ │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun) │ │ │ │ └───── month (1 - 12) │ │ │ └────────

React & Express server not getting api requests in production /build

∥☆過路亽.° 提交于 2020-04-17 22:50:21
问题 I have a React app running successfully locally and all api requests are successfully running from a separate server. When I run a build, the path to the api server is lost and no data is loaded. Below are a few screenshots... Loading data successfully from api. Pointing IIS to react /build folder using localhost:80. No data loading. Here is an example of an api call in my node/express server/index.js file app.get('/api/company', (req, res) => { api_helper.GET('https://****/api/company')

Running cron job at only specific date and time

为君一笑 提交于 2020-04-17 22:40:51
问题 In our express js application have a feature in admin module that he can send mail to users at specific dates (he can able to select a specific date and time). Say if the date and time is 2018-02-22@12.00 we need to run the email code at that time. I think this package will full fill our needs https://www.npmjs.com/package/node-schedule, Here is their documentation * * * * * * ┬ ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ │ │ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun) │ │ │ │ └───── month (1 - 12) │ │ │ └────────

How do I add Firebase Admin Auth into React app .env?

喜欢而已 提交于 2020-04-17 21:17:06
问题 Good question, to add the google auth from firebase for admin access, first you need the .json file from firebase, you can get it from your admin panel where you have auth setup go to the service account generate and download the JSON use it in your file how you wish... example my admin route //Use dotenv to read .env vars into Node require('dotenv').config(); const express = require('express'); var router = express.Router(); // Schema import const postModel = require('../models/postModel');

How do I add Firebase Admin Auth into React app .env?

ⅰ亾dé卋堺 提交于 2020-04-17 21:13:47
问题 Good question, to add the google auth from firebase for admin access, first you need the .json file from firebase, you can get it from your admin panel where you have auth setup go to the service account generate and download the JSON use it in your file how you wish... example my admin route //Use dotenv to read .env vars into Node require('dotenv').config(); const express = require('express'); var router = express.Router(); // Schema import const postModel = require('../models/postModel');