express

Can't add a new property to an object returned by Mongoose query [duplicate]

∥☆過路亽.° 提交于 2020-05-27 06:42:44
问题 This question already has answers here : Why can't you modify the data returned by a Mongoose Query (ex: findById) (2 answers) Closed 5 years ago . I'm coding an API with Node.js, MongoDB and Express. I can't seem to add a new property to the location objects I'm iterating through. I don't understand the issue with my code at all. loc is a plain object, it should work. Am I wrong? // ********************************** // GET Locations // ********************************** // Create endpoint

Access raw body of Stripe webhook in Nest.js

假如想象 提交于 2020-05-27 05:34:46
问题 I need to access the raw body of the webhook request from Stripe in my Nest.js application. Following this example, I added the below to the module which has a controller method that is needing the raw body. function addRawBody(req, res, next) { req.setEncoding('utf8'); let data = ''; req.on('data', (chunk) => { data += chunk; }); req.on('end', () => { req.rawBody = data; next(); }); } export class SubscriptionModule { configure(consumer: MiddlewareConsumer) { consumer .apply(addRawBody)

Access raw body of Stripe webhook in Nest.js

允我心安 提交于 2020-05-27 05:34:11
问题 I need to access the raw body of the webhook request from Stripe in my Nest.js application. Following this example, I added the below to the module which has a controller method that is needing the raw body. function addRawBody(req, res, next) { req.setEncoding('utf8'); let data = ''; req.on('data', (chunk) => { data += chunk; }); req.on('end', () => { req.rawBody = data; next(); }); } export class SubscriptionModule { configure(consumer: MiddlewareConsumer) { consumer .apply(addRawBody)

Embedding schemas is giving error

时光怂恿深爱的人放手 提交于 2020-05-27 05:30:26
问题 I am trying to embed schemas in other schemas that I have created, and I keep getting this error: I am not entirely sure what is going wrong here, but what I want to do is store references to my event schema and interests schema inside the user schema. If someone could tell me what I'm doing wrong that would be great thanks! EDIT: I am now receiving a new error: /Users/Dynee/node_modules/mongoose/lib/schema.js:421 throw new TypeError('Invalid value for schema Array path `' + prefix + key + '`

Embedding schemas is giving error

社会主义新天地 提交于 2020-05-27 05:30:07
问题 I am trying to embed schemas in other schemas that I have created, and I keep getting this error: I am not entirely sure what is going wrong here, but what I want to do is store references to my event schema and interests schema inside the user schema. If someone could tell me what I'm doing wrong that would be great thanks! EDIT: I am now receiving a new error: /Users/Dynee/node_modules/mongoose/lib/schema.js:421 throw new TypeError('Invalid value for schema Array path `' + prefix + key + '`

express.js global try/catch

守給你的承諾、 提交于 2020-05-26 02:42:28
问题 I'm developing a rest server on Node JS with Express. I'm trying to wrap all my endpoints in try\catch block, so a central point of error will response back to the sender with details. My problem that response (res instance) is alive for each of the endpoints methods, but I don't know how to make it global. try { app.get('/webhook', function (req, res) { webhook.register(req, res); }); app.get('/send', function (req, res) { sendAutoMessage('1004426036330995'); }); app.post('/webhook/subscribe

Sendgrid change href of link

你。 提交于 2020-05-25 11:34:00
问题 I am using Nodejs with Express and I am sending an email through Sendgrid, but Sendgrid is changing the href link var emailText = '<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body><a href="https://www.google.com">Here</a></body></html>' var from_email = new helper.Email('contact@test.com'); var to_email = new helper.Email('contact@test2.com'); var subject = 'Test'; var content = new helper.Content("text/html", emailText) var mail = new helper.Mail(from_email, subject, to_email,

sequelize - Cannot add foreign key constraint

扶醉桌前 提交于 2020-05-25 06:43:49
问题 I'm trying to set a 1:1 relation between two tables. RefreshToken table will have two foreignKey releated to Users table, as in this image: I used sequelize-auto to generate my sequelize models. Users model: module.exports = function(sequelize, DataTypes) { return sequelize.define('Users', { idUsers: { type: DataTypes.INTEGER(11), allowNull: false, primaryKey: true }, name: { type: DataTypes.STRING(45), allowNull: true }, mail: { type: DataTypes.STRING(45), allowNull: false, primaryKey: true

How to set log level in Winston/Node.js

萝らか妹 提交于 2020-05-25 05:44:45
问题 I am using Winston logging with my Node.js app and have defined a file transport. Throughout my code, I log using either logger.error , logger.warn , or logger.info . My question is, how do I specify the log level? Is there a config file and value that I can set so that only the appropriate log messages are logged? For example, I'd like the log level to be "info" in my development environment but "error" in production. 回答1: Looks like there is a level option in the options passed covered here

How to set log level in Winston/Node.js

丶灬走出姿态 提交于 2020-05-25 05:44:22
问题 I am using Winston logging with my Node.js app and have defined a file transport. Throughout my code, I log using either logger.error , logger.warn , or logger.info . My question is, how do I specify the log level? Is there a config file and value that I can set so that only the appropriate log messages are logged? For example, I'd like the log level to be "info" in my development environment but "error" in production. 回答1: Looks like there is a level option in the options passed covered here