FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Why Your Mongoose Hook is Returning 0 (The 'this' Lesson)
How-ToWeb Development

Why Your Mongoose Hook is Returning 0 (The 'this' Lesson)

via Dev.to JavaScriptDillibe Chisom Okorie1d ago

Building Yarncom Phase 2: Automation, Word Counts, and the "Arrow Function" Trap I’m currently on Day 2 of building Yarncom , a community-driven blogging API. Yesterday, I handled the Security Handshake. Today, I faced the Logic Layer. The goal was simple; Whenever a user saves a blog post, the API should automatically calculate the Estimated Reading Time based on a 200-words-per-minute average. Here is the technical breakdown of the challenges I faced and the code that solved them. 1. The Automation Logic (The Pre-Save Hook) Instead of forcing the user to tell us how long their post is, I used a Mongoose pre-save hook. This is a function that runs after the data is sent but before it’s persisted in the database. blogSchema.pre('save', async function() { if (this.body) { const wordsPerMinute = 200; const words = this.body.split(/\s+/).length; this.reading_time = Math.ceil(words / wordsPerMinute); console.log( Calculated: ${this.reading_time} min); } }); 2. The Trap: Arrow Functions vs.

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles

Why Feeling Lost in Programming Is Completely Normal
How-To

Why Feeling Lost in Programming Is Completely Normal

Medium Programming • 12h ago

⚡ Building a Production-Ready GDPR Export Feature in Symfony
How-To

⚡ Building a Production-Ready GDPR Export Feature in Symfony

Medium Programming • 12h ago

A gentle introduction to machine code, compilers, and LLVM
How-To

A gentle introduction to machine code, compilers, and LLVM

Medium Programming • 13h ago

Sony Promo Codes and Discounts: 45% Off
How-To

Sony Promo Codes and Discounts: 45% Off

Wired • 13h ago

I Wanted Extra Income — 7 Things I Learned the Hard Way
How-To

I Wanted Extra Income — 7 Things I Learned the Hard Way

Medium Programming • 14h ago

Discover More Articles