<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Code Meets Culture on Medium]]></title>
        <description><![CDATA[Stories by Code Meets Culture on Medium]]></description>
        <link>https://medium.com/@pritamroy1136?source=rss-b99eba57bf3d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mOO26c9h3LbAFFFSYKrKEA.png</url>
            <title>Stories by Code Meets Culture on Medium</title>
            <link>https://medium.com/@pritamroy1136?source=rss-b99eba57bf3d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:50:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pritamroy1136/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Silent Love]]></title>
            <link>https://medium.com/@pritamroy1136/silent-love-1d809e749062?source=rss-b99eba57bf3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d809e749062</guid>
            <category><![CDATA[litrature]]></category>
            <category><![CDATA[love]]></category>
            <category><![CDATA[silent-love]]></category>
            <dc:creator><![CDATA[Code Meets Culture]]></dc:creator>
            <pubDate>Wed, 11 Jun 2025 18:19:39 GMT</pubDate>
            <atom:updated>2025-06-11T18:19:39.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jnaQZW_YsS9UIZqx" /><figcaption>Photo by <a href="https://unsplash.com/@fadid000?utm_source=medium&amp;utm_medium=referral">Fadi Xd</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We often celebrate love that is loud — visible in grand gestures, spoken in bold declarations, easy for the world to notice. But there’s another kind of love. A quieter kind. One that doesn’t ask for attention or recognition. Silent love moves differently. It doesn’t rely on words or actions to prove itself. It simply exists — steady, constant, and deeply felt.</p><p>This kind of love doesn’t always come with reciprocation. It might not even be seen by the person it’s directed toward. But it’s real. Loving someone silently means carrying them in your thoughts, hoping for their happiness, and rooting for their peace, even from afar. There’s something honest and raw about that. It’s not about being noticed — it’s about genuinely wishing well for someone, without needing anything back.</p><p>Being loved is a beautiful thing, no doubt. But there’s something equally profound about being the one who loves — quietly, with no conditions. You find yourself creating space in your heart for someone, and over time, you get used to the silence. You learn to live with it. You learn to give without expecting. To admire without needing to be seen. To care without asking for more.</p><p>And in that process, you begin to understand the true strength of quiet affection. It teaches you patience, resilience, and a kind of grace that doesn’t shout. You start expressing yourself in ways that aren’t direct — maybe through a sketch, a verse, a photograph, a passing thought you keep to yourself. It’s subtle, but it’s meaningful.</p><p>Eventually, you stop worrying about whether anyone else understands it. Because it’s not about being understood. It’s about what it teaches you — about presence, about letting go, about loving without needing to hold on. That’s when it hits you why silence is often called powerful. Not because it hides something, but because it holds so much.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d809e749062" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three.js Fundamentals]]></title>
            <link>https://medium.com/@pritamroy1136/three-js-fundamentals-df317c84539f?source=rss-b99eba57bf3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/df317c84539f</guid>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[webgl]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Code Meets Culture]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 02:32:19 GMT</pubDate>
            <atom:updated>2024-11-28T02:32:19.546Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to the ultimate guide to Three.js! This tutorial is designed to give you a comprehensive understanding of Three.js — breaking it down step by step, with detailed explanations of every concept. Whether you’re a beginner or someone looking to fill in the gaps in your knowledge, this is the last tutorial you’ll ever need to start creating stunning 3D visuals in the browser.</p><h3>What Is Three.js?</h3><p><strong>Three.js</strong> is a powerful JavaScript library that enables developers to create 3D graphics that run directly in the browser. It simplifies the complexities of <strong>WebGL</strong>, which is the low-level browser API for rendering graphics. Think of WebGL as the engine and Three.js as the dashboard that makes it easy to drive.</p><p>Three.js powers everything from immersive games and data visualizations to educational tools and creative art projects. It’s widely used because it makes 3D accessible to developers without needing a deep understanding of computer graphics.</p><h3>Why Learn Three.js?</h3><p>Three.js opens a world of creative possibilities:</p><ul><li><strong>Interactive visualizations</strong>: Showcase data in engaging ways.</li><li><strong>Games and simulations</strong>: Build browser-based 3D experiences.</li><li><strong>Virtual Reality (VR)</strong> and <strong>Augmented Reality (AR)</strong>: Create futuristic applications using WebXR.</li><li><strong>Art and creativity</strong>: Bring your imagination to life in 3D space.</li></ul><h3>Setting Up the Development Environment</h3><p>Before we dive into coding, let’s set up everything you need.</p><h3>Tools You Need:</h3><ol><li><strong>Text Editor</strong>: <a href="https://code.visualstudio.com/">VS Code</a> is the most popular choice.</li><li><strong>Local Server</strong>: Browsers often block local files from running properly, so you’ll need a simple HTTP server. Use:</li></ol><ul><li><a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer">Live Server</a> (VS Code extension).</li><li>http-server, which you can install via Node.js:</li></ul><pre>npm install -g http-server</pre><p><strong>3. Basic JavaScript Knowledge</strong>: A foundational understanding of JavaScript and ES6 syntax will help.</p><h3>Installing Three.js</h3><h4>Option 1: Use a CDN (Quick and Easy)</h4><p>For simple projects, you can include Three.js directly in your HTML file:</p><pre>&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/three.js/r146/three.min.js&quot;&gt;&lt;/script&gt;</pre><h4>Option 2: Use npm (Preferred for Larger Projects)</h4><p>If you’re building a more complex application, install Three.js using npm:</p><pre>npm install three</pre><p>This allows you to manage dependencies better and import specific modules in your code.</p><h3>Core Components of Three.js</h3><p>Every Three.js project is built around six main components: <strong>Scene</strong>, <strong>Camera</strong>, <strong>Renderer</strong>, <strong>Objects</strong>, <strong>Materials</strong>, and <strong>Lights</strong>. Let’s explore these in detail.</p><h3>1. Scene: The Stage of Your 3D World</h3><p>The scene is where everything happens. It’s the container for your 3D objects, lights, and cameras. Think of it as the stage on which your 3D world is built.</p><pre>const scene = new THREE.Scene();</pre><p>You can add objects to the scene like this:</p><pre>scene.add(object);</pre><p>For instance:</p><pre>const cube = new THREE.Mesh(<br>  new THREE.BoxGeometry(1, 1, 1),<br>  new THREE.MeshBasicMaterial({ color: 0xff0000 })<br>);<br>scene.add(cube);</pre><h3>2. Camera: Your Point of View</h3><p>A camera defines how you see the 3D world. Without a camera, your 3D objects wouldn’t be visible.</p><h4>Types of Cameras:</h4><ol><li><strong>PerspectiveCamera</strong>: Simulates human vision — objects farther away appear smaller.</li></ol><pre>const camera = new THREE.PerspectiveCamera(<br>  75, // Field of view (in degrees)<br>  window.innerWidth / window.innerHeight, // Aspect ratio<br>  0.1, // Near clipping plane<br>  1000 // Far clipping plane<br>);<br>camera.position.z = 5; // Move the camera back to view the objects</pre><p><strong>2. OrthographicCamera</strong>: Keeps objects the same size regardless of distance, useful for 2D-like projections.</p><pre>const camera = new THREE.OrthographicCamera(-5, 5, 5, -5, 0.1, 1000);</pre><h3>3. Renderer: Turning 3D Scenes into Pixels</h3><p>The renderer translates your 3D scene into a 2D image that your browser can display. Think of it as the artist painting the picture you’ll see on your screen.</p><pre>const renderer = new THREE.WebGLRenderer();<br>renderer.setSize(window.innerWidth, window.innerHeight); // Full-screen canvas<br>document.body.appendChild(renderer.domElement); // Attach renderer&#39;s canvas to the DOM</pre><p>To render the scene:</p><pre>renderer.render(scene, camera);</pre><h3>4. Objects: Shapes and Geometry</h3><p>Objects are the visible elements in your 3D scene. They’re created by combining <strong>geometry</strong> (shape) with <strong>materials</strong> (appearance).</p><h4>Geometry</h4><p>Geometry defines the shape of an object:</p><ul><li><strong>BoxGeometry</strong>: A cube.</li><li><strong>SphereGeometry</strong>: A sphere.</li><li><strong>PlaneGeometry</strong>: A flat rectangle.</li><li><strong>TorusGeometry</strong>: A doughnut shape.</li></ul><pre>const geometry = new THREE.BoxGeometry(1, 1, 1); // Width, height, depth</pre><h3>5. Materials: Appearance and Style</h3><p>Materials define how objects look — color, texture, reflectivity, or transparency.</p><h4>Common Material Types:</h4><ol><li><strong>MeshBasicMaterial</strong>: A simple material that doesn’t react to light.</li></ol><pre>const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });</pre><p><strong>2. MeshStandardMaterial</strong>: A realistic material that reacts to light.</p><pre>const material = new THREE.MeshStandardMaterial({ color: 0x0077ff });</pre><h4>Combining Geometry and Material:</h4><pre>const material = new THREE.MeshStandardMaterial({ color: 0x0077ff });<br>const cube = new THREE.Mesh(geometry, material);<br>scene.add(cube);</pre><h3>6. Lights: Bringing Your Scene to Life</h3><p>Lights add depth and realism to your 3D scene. Without lights, your objects will be flat and lifeless.</p><h4>Types of Lights:</h4><ol><li><strong>AmbientLight</strong>: Soft, uniform light across the scene.</li></ol><pre>const ambientLight = new THREE.AmbientLight(0xffffff, 0.5); // Color and intensity scene.add(ambientLight);</pre><p><strong>2. PointLight</strong>: Emits light in all directions from a single point (like a bulb).</p><pre>const pointLight = new THREE.PointLight(0xffffff, 1);<br>pointLight.position.set(5, 5, 5); // Position of the light<br>scene.add(pointLight);</pre><p><strong>3. DirectionalLight</strong>: Parallel rays like sunlight.</p><pre>const directionalLight = new THREE.DirectionalLight(0xffffff, 1); <br>directionalLight.position.set(5, 5, 5); scene.add(directionalLight);</pre><h3>Putting It All Together: Your First Scene</h3><p>Let’s build a simple rotating cube illuminated by a point light.</p><pre>// Import Three.js<br>import * as THREE from &#39;three&#39;;</pre><pre>// Create the scene<br>const scene = new THREE.Scene();</pre><pre>// Create the camera<br>const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);<br>camera.position.z = 5;</pre><pre>// Create the renderer<br>const renderer = new THREE.WebGLRenderer();<br>renderer.setSize(window.innerWidth, window.innerHeight);<br>document.body.appendChild(renderer.domElement);</pre><pre>// Create geometry and material<br>const geometry = new THREE.BoxGeometry();<br>const material = new THREE.MeshStandardMaterial({ color: 0x0077ff });<br>const cube = new THREE.Mesh(geometry, material);<br>scene.add(cube);</pre><pre>// Add a light<br>const pointLight = new THREE.PointLight(0xffffff, 1);<br>pointLight.position.set(5, 5, 5);<br>scene.add(pointLight);</pre><pre>// Animation loop<br>function animate() {<br>  requestAnimationFrame(animate);</pre><pre>  // Rotate the cube<br>  cube.rotation.x += 0.01;<br>  cube.rotation.y += 0.01;</pre><pre>  // Render the scene<br>  renderer.render(scene, camera);<br>}<br>animate();</pre><h3>Advanced Features</h3><h3>Shadows</h3><p>Enable shadows for more realistic rendering:</p><pre>renderer.shadowMap.enabled = true;</pre><pre>cube.castShadow = true;<br>cube.receiveShadow = true;</pre><pre>pointLight.castShadow = true;</pre><h3>Environment Maps</h3><p>Simulate reflections using panoramic textures:</p><pre>const loader = new THREE.CubeTextureLoader();<br>const environmentMap = loader.load([<br>  &#39;px.jpg&#39;, &#39;nx.jpg&#39;,<br>  &#39;py.jpg&#39;, &#39;ny.jpg&#39;,<br>  &#39;pz.jpg&#39;, &#39;nz.jpg&#39;,<br>]);<br>scene.background = environmentMap;</pre><h3>7. Tips and Tricks for Optimizing Performance</h3><ol><li><strong>Use lower polygon geometries</strong> for simpler objects.</li><li><strong>Bake lighting</strong> when creating static scenes.</li><li>Use LOD (Level of Detail) to reduce detail for distant objects.</li><li>Use Frustum Culling to render only visible objects.</li></ol><h3>8. Resources to Go Further</h3><ul><li><a href="https://threejs.org/docs/">Official Three.js Documentation</a></li><li>Tutorials: <a href="https://threejs.org/manual/">Three.js Fundamentals</a></li><li>Three.js <a href="https://youtu.be/KM64t3pA4fs?si=jOAqyZQ4_In9k0iZ">Video tutorial</a></li></ul><h3>Final Thoughts</h3><p>Three.js is incredibly powerful, yet accessible. From the basics of geometry and lighting to advanced features like shadows and environment maps, this tutorial has equipped you with a solid foundation. Now it’s time to experiment, iterate, and bring your 3D ideas to life.</p><p>The web is your canvas — start creating! 🌟</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df317c84539f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Much Time Does It Really Take to Learn a Skill: 10,000 Hours or 20 Hours?]]></title>
            <link>https://medium.com/@pritamroy1136/how-much-time-does-it-really-take-to-learn-a-skill-10-000-hours-or-20-hours-7654055cf587?source=rss-b99eba57bf3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7654055cf587</guid>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[skills-development]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[learing]]></category>
            <dc:creator><![CDATA[Code Meets Culture]]></dc:creator>
            <pubDate>Sun, 24 Nov 2024 12:11:18 GMT</pubDate>
            <atom:updated>2024-11-24T12:11:18.568Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bOOSuwIBGiZTwdUn" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The question of how long it takes to master or become proficient in a new skill has intrigued learners for years. Two polarizing perspectives dominate the discourse: Malcolm Gladwell’s <strong>10,000-hour rule</strong> and Josh Kaufman’s <strong>20-hour method</strong>. Gladwell popularized the idea that 10,000 hours of deliberate practice is the key to achieving world-class mastery, while Kaufman proposes that you can become reasonably competent in just 20 hours of focused practice.</p><p>In this article, we’ll dissect both ideas, compare their contexts, and help you understand how much time you really need to invest based on your goals and the nature of the skill.</p><h3>The Origins of the 10,000-Hour Rule</h3><p>The <strong>10,000-hour rule</strong> stems from research by psychologist Anders Ericsson, who studied elite performers across disciplines like music, chess, and sports. Ericsson found that achieving world-class expertise required thousands of hours of <strong>deliberate practice</strong> — a focused, structured effort designed to improve specific aspects of performance.</p><p>Gladwell, in his book <em>Outliers</em>, took this concept further, asserting that 10,000 hours is the threshold for mastery in virtually any field. Examples cited in the book include The Beatles, who honed their craft through extensive live performances, and Bill Gates, who spent thousands of hours programming during his youth.</p><h3>Key Elements of the 10,000-Hour Rule</h3><ol><li><strong>Deliberate Practice</strong>: Casual effort won’t suffice. Mastery demands intentional, goal-driven practice with consistent feedback.</li><li><strong>Complex Skills</strong>: The rule applies primarily to highly competitive or intricate fields, such as classical music, chess, and professional sports.</li><li><strong>Timeframe</strong>: While 10,000 hours roughly equates to a decade of consistent effort (assuming 20 hours per week), the pace varies depending on individual commitment and circumstances.</li></ol><p>While the rule provides a benchmark for elite performance, it’s not without criticism. Critics argue that:</p><ul><li>It overlooks individual aptitude and the quality of practice.</li><li>It’s not universally applicable to all skills, especially simpler ones.</li><li>It may discourage people who feel intimidated by such a large number.</li></ul><h3>The Case for 20 Hours: Josh Kaufman’s Perspective</h3><p>On the opposite end of the spectrum, Josh Kaufman challenges the 10,000-hour rule with his book <em>The First 20 Hours: How to Learn Anything… Fast!</em>. Kaufman argues that you don’t need thousands of hours to acquire functional proficiency in most skills. Instead, he suggests that the first 20 hours of <strong>focused, intentional learning</strong> can yield impressive results.</p><h3>The Principles of the 20-Hour Method</h3><ol><li><strong>Deconstruct the Skill</strong>: Break the skill into smaller, manageable components to identify what’s most essential.</li><li><strong>Focus on High-Leverage Activities</strong>: Prioritize the elements that deliver the greatest impact.</li><li><strong>Eliminate Barriers</strong>: Remove distractions and create a conducive learning environment.</li><li><strong>Commit to Practice</strong>: Practice consistently for at least 20 hours, tracking your progress.</li><li><strong>Embrace Discomfort</strong>: Accept that the initial stages will be challenging and awkward.</li></ol><h3>Examples of Skills Suited for the 20-Hour Rule</h3><ul><li>Learning basic guitar chords to play simple songs.</li><li>Picking up conversational phrases in a new language.</li><li>Acquiring fundamental programming skills to create basic applications.</li><li>Learning to cook a handful of dishes.</li></ul><p>Kaufman’s method appeals to people looking for quick wins and functional competence rather than mastery.</p><h3>The Core Difference: Mastery vs. Competence</h3><p>The disparity between the 10,000-hour and 20-hour frameworks largely boils down to <strong>intent</strong> and <strong>goal-setting</strong>.</p><ul><li><strong>The 10,000-hour rule</strong> is about achieving <strong>expert-level mastery</strong> in a complex, competitive domain. Think of concert pianists, professional athletes, or renowned scientists. Mastery demands consistent effort over years.</li><li><strong>The 20-hour method</strong> is about attaining <strong>basic proficiency</strong> or practical utility. It’s ideal for hobbies, casual interests, or workplace skills that don’t require high-level expertise.</li></ul><p>Let’s illustrate this difference with examples:</p><p>Skill Competence Goal (20 Hours) Mastery Goal (10,000 Hours) Piano Learn to play a few songs Perform in international competitions Programming Build a simple website Become a software engineering expert Language Learning Hold basic conversations Achieve fluency and cultural nuance Sports Play casually with friends Compete at a professional level</p><h3>Factors That Influence Learning Time</h3><p>The time required to learn a skill depends on several factors, including the complexity of the skill, individual aptitude, learning methods, and environmental support. Here’s a closer look:</p><h3>1. Skill Complexity</h3><ul><li><strong>Simple skills</strong> (e.g., tying a knot or brewing coffee) can be learned in minutes or hours.</li><li><strong>Moderately complex skills</strong> (e.g., playing a musical instrument or coding) may take weeks to months for basic competence.</li><li><strong>Highly complex skills</strong> (e.g., becoming a surgeon or mastering chess) require years of rigorous practice.</li></ul><h3>2. Individual Factors</h3><ul><li><strong>Prior experience</strong>: Skills related to your existing knowledge are easier to learn.</li><li><strong>Cognitive ability</strong>: Natural aptitude and problem-solving skills can accelerate learning.</li><li><strong>Motivation and consistency</strong>: Passion and dedication often outweigh raw talent.</li></ul><h3>3. Quality of Practice</h3><ul><li>Time spent practicing is important, but the <strong>method</strong> of practice matters more. Effective learning involves:</li><li>Deliberate practice with feedback.</li><li>Spaced repetition for memory retention.</li><li>Experimentation and problem-solving.</li></ul><h3>4. Access to Resources</h3><ul><li>Mentorship, tools, and learning materials can significantly impact your progress. Structured courses or expert guidance often shorten learning curves.</li></ul><h3>Finding the Right Balance: A Practical Approach</h3><p>The dichotomy between 10,000 hours and 20 hours doesn’t mean you must choose one or the other. Instead, focus on what aligns with your <strong>goals, time availability, and interests</strong>. Here’s a practical roadmap:</p><h3>1. Define Your Goals</h3><ul><li><strong>Competence</strong>: If you want functional knowledge or to explore a hobby, adopt the 20-hour approach.</li><li><strong>Mastery</strong>: If your goal is to excel professionally or competitively, be prepared to invest thousands of hours.</li></ul><h3>2. Start Small</h3><ul><li>Begin with Kaufman’s principles to gain foundational skills. The 20-hour method is an excellent way to test your interest and build confidence.</li></ul><h3>3. Evaluate Progress</h3><ul><li>After the initial 20 hours, decide if you want to deepen your expertise. For some skills, 20 hours might suffice; for others, you may choose to continue.</li></ul><h3>4. Commit to Lifelong Learning</h3><ul><li>Mastery isn’t a destination but a journey. Even after reaching 10,000 hours, professionals continue to refine their skills.</li></ul><h3>Real-Life Case Studies</h3><h3>The Beatles: A 10,000-Hour Success Story</h3><p>The Beatles famously logged thousands of hours playing live shows in Hamburg before achieving global fame. Their extensive practice helped them hone their songwriting, stage presence, and musical innovation — clear evidence of the 10,000-hour rule in action.</p><h3>Tim Ferriss: Accelerating Learning</h3><p>Author Tim Ferriss is a strong advocate of rapid skill acquisition. In his book <em>The 4-Hour Chef</em>, he demonstrates how breaking skills into small steps and applying focused effort can lead to rapid progress — echoing Kaufman’s principles.</p><h3>Language Learning</h3><ul><li><strong>20 Hours</strong>: Apps like Duolingo or Rosetta Stone can help you learn basic vocabulary and phrases quickly.</li><li><strong>10,000 Hours</strong>: To achieve native-like fluency and cultural mastery, years of immersion and advanced study are required.</li></ul><h3>Conclusion: How Much Time Do You Really Need?</h3><p>The debate between 10,000 hours and 20 hours boils down to your objectives:</p><ul><li>If you’re pursuing <strong>world-class mastery</strong>, the 10,000-hour rule serves as a realistic benchmark, though not an absolute requirement.</li><li>If you’re aiming for <strong>quick proficiency</strong>, 20 focused hours can provide remarkable results.</li></ul><p>Ultimately, the time it takes to learn a skill isn’t just about the hours logged but the <strong>quality of practice</strong> and your <strong>motivation</strong>. By understanding your goals and adopting the right approach, you can make the most of your learning journey — whether it’s 20 hours, 10,000 hours, or somewhere in between.</p><p>What skill are you excited to learn next?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7654055cf587" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I plan a MERN stack project.]]></title>
            <link>https://medium.com/@pritamroy1136/how-i-plan-a-mern-stack-project-25b2723ab8b7?source=rss-b99eba57bf3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/25b2723ab8b7</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mern-stack]]></category>
            <category><![CDATA[planning]]></category>
            <category><![CDATA[medium]]></category>
            <dc:creator><![CDATA[Code Meets Culture]]></dc:creator>
            <pubDate>Thu, 07 Nov 2024 02:31:58 GMT</pubDate>
            <atom:updated>2024-11-07T02:31:58.484Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b4pUdggTl6HSiwWQ" /><figcaption>Photo by <a href="https://unsplash.com/@cathrynlavery?utm_source=medium&amp;utm_medium=referral">Cathryn Lavery</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Planning a MERN stack project effectively is crucial to ensure smooth development and a successful outcome. The MERN stack — consisting of MongoDB, Express.js, React, and Node.js — provides a robust foundation for building full-stack JavaScript applications. Here’s a comprehensive guide on how to plan a MERN stack project to keep everything organized, efficient, and well-structured.</p><h3>1. Define Project Goals and Objectives</h3><p>Before jumping into the technical details, it’s essential to clarify the purpose of your project. Ask yourself the following:</p><ul><li><strong>What problem does this project solve?</strong></li><li><strong>Who is the target audience?</strong></li><li><strong>What features are necessary to achieve the core functionality?</strong></li></ul><p>Having a clear understanding of the goals will help you make informed decisions about the scope, technology, and resources required. For example, if you’re building a social media platform, your objectives might include user authentication, real-time notifications, a responsive UI, and secure data storage.</p><h3>2. Outline Core Features and User Stories</h3><p>With your objectives in mind, create a list of <strong>core features</strong>. These might include:</p><ul><li><strong>Authentication and Authorization</strong>: Allow users to sign up, log in, and access certain parts of the application based on roles.</li><li><strong>CRUD Operations</strong>: Outline the main actions users will perform, like creating, reading, updating, or deleting data.</li><li><strong>Responsive UI</strong>: Define which components will adapt to different screen sizes.</li><li><strong>Real-Time Data</strong>: List any features that will require real-time data updates, such as notifications, chat, or live updates.</li></ul><p>Translate these features into <strong>user stories</strong> to capture requirements from the end-user’s perspective. For instance, a user story for a task management app could be: “As a user, I want to create a new task with a title, description, and due date so that I can manage my work effectively.”</p><h3>3. Choose a Project Structure</h3><p>Organizing your codebase is crucial for maintainability, especially in large projects. Here’s a basic MERN stack structure to get started:</p><pre>project-name/<br>├── client/        # React frontend<br>│   ├── public/    # Public assets<br>│   ├── src/       # Source files<br>│       ├── components/<br>│       ├── pages/<br>│       ├── services/<br>│       ├── App.js<br>├── server/        # Node and Express backend<br>│   ├── controllers/<br>│   ├── models/<br>│   ├── routes/<br>│   ├── middleware/<br>│   ├── config/<br>│   ├── index.js<br>├── .env<br>├── package.json</pre><p>A clear structure helps developers quickly find files, understand dependencies, and maintain a modular codebase. For example, having separate directories for models and controllers promotes the MVC (Model-View-Controller) pattern, where models handle database operations, and controllers manage business logic.</p><h3>4. Set Up Your Tech Stack and Tools</h3><p>Choose your tools for each layer of the MERN stack:</p><ul><li><strong>MongoDB</strong>: Use MongoDB as your NoSQL database to store structured and unstructured data.</li><li><strong>Express.js</strong>: Set up the Express framework to create the backend API and handle HTTP requests.</li><li><strong>React</strong>: Use React for a dynamic and responsive frontend UI.</li><li><strong>Node.js</strong>: Utilize Node.js for server-side JavaScript execution.</li></ul><p>Additionally, integrate tools that can help streamline development, such as:</p><ul><li><strong>Postman</strong>: For API testing.</li><li><strong>Mongoose</strong>: For MongoDB object modeling, making database queries simpler.</li><li><strong>JWT (JSON Web Tokens)</strong>: For secure user authentication.</li><li><strong>Bcrypt</strong>: For password hashing.</li><li><strong>Redux</strong> (optional): For managing global state in larger projects.</li></ul><h3>5. Design the Database Schema</h3><p>A well-planned database schema is key to efficient data management. Think about the entities (or models) your application will need and how they relate. In a social media app, for example, you may have User, Post, Comment, and Like models with relations defined by MongoDB references.</p><p>Example schema for a User model in MongoDB using Mongoose:</p><pre>const userSchema = new mongoose.Schema({<br>  username: { type: String, required: true, unique: true },<br>  password: { type: String, required: true },<br>  email: { type: String, required: true, unique: true },<br>  createdAt: { type: Date, default: Date.now }<br>});</pre><h3>6. Plan Your API Endpoints</h3><p>Design API endpoints that reflect the core features. Each endpoint should correspond to a specific functionality. For example:</p><ul><li>POST /api/auth/register - Register a new user.</li><li>POST /api/auth/login - Log in a user and return a JWT.</li><li>GET /api/posts - Retrieve all posts.</li><li>POST /api/posts - Create a new post.</li></ul><p>Clearly define the expected request and response format for each endpoint. You can document these in a tool like Swagger or simply in a markdown file for reference during development.</p><h3>7. Implement Authentication and Authorization</h3><p>Secure your app by implementing authentication and authorization early in the development process. Use JWT for stateless authentication, where tokens are issued at login and verified with each request to secure protected routes. Here’s a sample Express middleware for verifying a JWT token:</p><pre>const verifyToken = (req, res, next) =&gt; {<br>  const token = req.header(&quot;Authorization&quot;).replace(&quot;Bearer &quot;, &quot;&quot;);<br>  jwt.verify(token, process.env.JWT_SECRET, (err, decoded) =&gt; {<br>    if (err) return res.status(401).send(&quot;Unauthorized&quot;);<br>    req.user = decoded;<br>    next();<br>  });<br>};</pre><p>This ensures that only authenticated users can access protected resources, adding a layer of security to the application.</p><h3>8. Establish Development Milestones</h3><p>Break down development into <strong>milestones</strong> to track progress effectively. For instance:</p><ol><li><strong>Milestone 1</strong>: Set up project structure, install dependencies, and establish a Git repository.</li><li><strong>Milestone 2</strong>: Implement basic backend functionality like user registration and login.</li><li><strong>Milestone 3</strong>: Develop core frontend components and integrate them with the backend.</li><li><strong>Milestone 4</strong>: Add additional features like search, filtering, and user settings.</li><li><strong>Milestone 5</strong>: Test, deploy, and optimize the app for production.</li></ol><p>Set realistic deadlines for each milestone to keep the project on track and maintain momentum.</p><h3>9. Focus on UI/UX Design</h3><p>Designing a user-friendly interface is essential for user satisfaction. Sketch or wireframe the main screens of your application using tools like Figma, Sketch, or Adobe XD. Focus on creating an intuitive navigation structure, responsive design, and a consistent look and feel.</p><p>In React, you can build reusable UI components like buttons, cards, and form inputs. For a consistent and visually appealing UI, consider using a CSS framework like Tailwind CSS, Material-UI, or Bootstrap.</p><h3>10. Test Throughout Development</h3><p>Testing ensures the stability of your application. Use a mix of testing techniques:</p><ul><li><strong>Unit Testing</strong>: Test individual components, especially for the frontend. Tools like Jest and React Testing Library are useful here.</li><li><strong>Integration Testing</strong>: Test interactions between different parts of your app, like API endpoints.</li><li><strong>End-to-End Testing</strong>: Simulate user flows using tools like Cypress or Selenium.</li></ul><p>Automated testing helps catch bugs early and reduces the likelihood of issues in production.</p><h3>11. Deploy and Monitor the Application</h3><p>Once development is complete, deploy your MERN app to a platform like <strong>Render, Vercel, Heroku, or AWS</strong>. Make sure to set up a CI/CD pipeline to automate the deployment process.</p><h3>12. Gather Feedback and Iterate</h3><p>After deployment, gather feedback from users to identify improvements. Monitor the application’s performance and make iterative changes to enhance functionality, UI, and security.</p><p>Effective planning in a MERN stack project covers clear goals, a well-defined project structure, robust authentication, and a detailed roadmap for development. By following these steps, you can ensure a smoother development journey, delivering a product that meets user needs and stands the test of time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25b2723ab8b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Essential Yet Underrated Node.js Packages Every Developer Should Explore]]></title>
            <link>https://medium.com/@pritamroy1136/5-essential-yet-underrated-node-js-packages-every-developer-should-explore-7ab5cffa55e1?source=rss-b99eba57bf3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ab5cffa55e1</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Code Meets Culture]]></dc:creator>
            <pubDate>Fri, 01 Nov 2024 08:46:35 GMT</pubDate>
            <atom:updated>2024-11-01T08:46:35.145Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6sTMnmk53im-Bsgo" /><figcaption>Photo by <a href="https://unsplash.com/@6heinz3r?utm_source=medium&amp;utm_medium=referral">Gabriel Heinzer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Node.js is known for its speed, versatility, and vast ecosystem of packages that make backend development efficient and effective. While popular packages like Express and Mongoose are often the go-tos, some lesser-known packages offer powerful functionality for handling everyday needs. Here’s a closer look at five essential but underrated Node.js packages: node-cron, multer, socket.io, morgan, and nodemailer. Each of these packages tackles specific backend tasks, from scheduling jobs to enabling real-time communication, making your application more dynamic, responsive, and user-friendly.</p><ol><li>node-cron: Automated Task Scheduling</li></ol><p><strong>What It Does:</strong><br>node-cron is a powerful tool for scheduling tasks in your application, like sending daily reports, cleaning up files, or sending automated emails. The package allows you to define custom schedules using cron syntax, making it easy to execute tasks at specified intervals, such as hourly, daily, weekly, or even every minute.</p><p><strong>Why Use It:</strong><br>Scheduling tasks in Node.js is often crucial for backend functionality. While traditional CRON jobs are defined directly in the OS, node-cron brings that capability directly into your Node.js app, enabling custom schedules and better control over timed functions.</p><p><strong>Code Example:</strong> Here’s how to set up a simple scheduled task that logs “Hello, World!” every minute.</p><pre>// Import the node-cron package<br>const cron = require(&#39;node-cron&#39;);<br><br>// Schedule a task to run every hour<br>cron.schedule(&#39;0 * * * *&#39;, () =&gt; {<br>  // The task you want to run every hour<br>  console.log(&#39;This task runs at the start of every hour.&#39;);<br>  <br>  // You could replace this log with code to perform any task,<br>  // like cleaning up temp files, sending reminder emails, etc.<br>});</pre><p><strong>Explanation:</strong><br>The * * * * * syntax defines the schedule. In this case, every * represents a unit of time, from minute to day. So * * * * * means &quot;run every minute.&quot; Change this pattern to fit your requirements, such as 0 0 * * * to run once daily at midnight. Here is the documentation <a href="https://www.npmjs.com/package/node-cron">link</a>.</p><h3>2. multer: Managing File Uploads</h3><p><strong>What It Does:</strong><br>multer simplifies handling file uploads in your Node.js applications. This is particularly helpful for features requiring users to upload files, such as profile pictures, document submissions, or media content. multer processes the uploaded files, making them easily accessible for further handling.</p><p><strong>Why Use It:</strong><br>Handling file uploads without multer would require a lot of manual configuration. multer takes care of parsing and storing the files, saving them to disk or memory and providing powerful customization options.</p><p><strong>Code Example:</strong> Here’s an endpoint for handling image uploads to the uploads folder.</p><pre>// Import required packages<br>const express = require(&#39;express&#39;);<br>const multer = require(&#39;multer&#39;);<br>const app = express();<br><br>// Configure multer storage options<br>const storage = multer.diskStorage({<br>  // Define the destination folder for uploaded files<br>  destination: (req, file, cb) =&gt; {<br>    cb(null, &#39;uploads/&#39;); // Uploads go to the &#39;uploads&#39; directory<br>  },<br>  // Define the filename format to avoid duplicates<br>  filename: (req, file, cb) =&gt; {<br>    // Prefixing with Date.now() for a unique name<br>    cb(null, Date.now() + &#39;-&#39; + file.originalname);<br>  }<br>});<br><br>// Initialize multer with the storage settings<br>const upload = multer({ storage: storage });<br><br>// Endpoint to handle file upload with &#39;single&#39; middleware for one file<br>app.post(&#39;/upload&#39;, upload.single(&#39;file&#39;), (req, res) =&gt; {<br>  // req.file contains file information<br>  res.send(&#39;File uploaded successfully!&#39;);<br>});<br><br>app.listen(3000, () =&gt; console.log(&#39;Server running on port 3000&#39;));</pre><p><strong>Explanation:</strong><br>The upload.single(&#39;file&#39;) middleware processes one file at a time, and the file is accessible through req.file. Each file is stored in the uploads directory, with a unique name based on the current timestamp to avoid overwriting. Here is the documentation <a href="https://www.npmjs.com/package/multer">link</a>.</p><h3>3. socket.io: Real-Time Communication</h3><p><strong>What It Does:</strong><br>socket.io enables real-time, bidirectional communication between client and server. This functionality is essential for applications like chat platforms, live notifications, collaborative tools, or online games, where users require instant updates without refreshing the page.</p><p><strong>Why Use It:</strong><br>WebSocket technology allows faster and more efficient communication than traditional HTTP requests. socket.io builds on WebSocket with additional features like automatic reconnection and broadcasting, making it ideal for real-time applications.</p><p><strong>Code Example:</strong> Here’s a simple setup for a real-time chat server with socket.io.</p><pre>// Import required modules<br>const express = require(&#39;express&#39;);<br>const http = require(&#39;http&#39;);<br>const { Server } = require(&#39;socket.io&#39;);<br><br>const app = express();<br>const server = http.createServer(app);<br>const io = new Server(server);<br><br>// When a client connects to the server<br>io.on(&#39;connection&#39;, (socket) =&gt; {<br>  console.log(&#39;A user connected&#39;);<br><br>  // Listen for &#39;chat message&#39; events from the client<br>  socket.on(&#39;chat message&#39;, (msg) =&gt; {<br>    // Broadcast the message to all connected clients<br>    io.emit(&#39;chat message&#39;, msg);<br>  });<br><br>  // Detect when a user disconnects<br>  socket.on(&#39;disconnect&#39;, () =&gt; {<br>    console.log(&#39;User disconnected&#39;);<br>  });<br>});<br><br>// Serve the app<br>server.listen(3000, () =&gt; console.log(&#39;Server listening on port 3000&#39;));</pre><p><strong>Explanation:</strong><br>The server emits messages to all connected clients using io.emit(&#39;chat message&#39;, msg), allowing every user to see the messages in real time. The socket.on listeners wait for events from the client, while io.on handles the connection events on the server. Here is the documentation <a href="https://socket.io/docs/v4">link</a>.</p><h3>4. morgan: Logging HTTP Requests</h3><p><strong>What It Does:</strong><br>morgan is a simple HTTP request logger for Node.js applications. It logs every incoming request to the server, showing details like method, URL, status, and response time, which are invaluable for debugging and monitoring traffic.</p><p><strong>Why Use It:</strong><br>By logging each request, morgan provides insights into API usage and server health, making it easier to diagnose errors and optimize performance. morgan can also output logs in various formats (e.g., concise, detailed) to suit different needs.</p><p><strong>Code Example:</strong> Adding morgan to log all HTTP requests.</p><pre>// Import required modules<br>const express = require(&#39;express&#39;);<br>const morgan = require(&#39;morgan&#39;);<br>const app = express();<br><br>// Setup morgan to log all HTTP requests in &#39;combined&#39; format<br>// &#39;combined&#39; format provides detailed logs including IP, method, URL, and more<br>app.use(morgan(&#39;combined&#39;));<br><br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello, World!&#39;);<br>});<br><br>app.listen(3000, () =&gt; console.log(&#39;Server running on port 3000&#39;));</pre><p><strong>Explanation:</strong><br>Here, morgan(&#39;dev&#39;) uses the &quot;dev&quot; format, which logs method, URL, status, and response time for each request. Other formats like combined provide more details if needed, and the logs help identify bottlenecks or high-traffic endpoints. Here is the documentation <a href="https://www.npmjs.com/package/morgan">link</a>.</p><h3>5. nodemailer: Sending Emails</h3><p><strong>What It Does:</strong><br>nodemailer is a module for sending emails directly from your Node.js applications. It supports multiple email services, including Gmail and custom SMTP configurations, making it ideal for applications requiring notifications, alerts, or email verifications.</p><p><strong>Why Use It:</strong><br>Email remains a vital form of communication for user verification, password recovery, and notifications. nodemailer simplifies this process, providing easy-to-use methods to send emails with attachments and even HTML templates.</p><p><strong>Code Example:</strong> Send a basic email using nodemailer.</p><pre>// Import nodemailer package<br>const nodemailer = require(&#39;nodemailer&#39;);<br><br>// Configure nodemailer with Gmail as the email service<br>// Replace with actual email credentials<br>const transporter = nodemailer.createTransport({<br>  service: &#39;gmail&#39;,<br>  auth: {<br>    user: &#39;your-email@gmail.com&#39;, // Your Gmail address<br>    pass: &#39;your-password&#39; // Your Gmail password or app password<br>  }<br>});<br><br>// Define email content and recipient details<br>const mailOptions = {<br>  from: &#39;your-email@gmail.com&#39;,       // Sender&#39;s email<br>  to: &#39;recipient@example.com&#39;,        // Recipient&#39;s email<br>  subject: &#39;Test Email from Node.js&#39;, // Email subject<br>  text: &#39;Hello, this is a test email sent from Node.js!&#39; // Plain-text body<br>};<br><br>// Send the email<br>transporter.sendMail(mailOptions, (error, info) =&gt; {<br>  if (error) {<br>    console.log(&#39;Error sending email:&#39;, error);<br>  } else {<br>    console.log(&#39;Email sent successfully:&#39;, info.response);<br>  }<br>});</pre><p><strong>Explanation:</strong><br>In this example, the transporter is configured to use Gmail (you’ll need to enable less secure apps in Gmail settings for this to work). The mailOptions object specifies the email details, and transporter.sendMail() sends the email. Adjust this configuration to suit your needs or integrate it into your application’s notification system. Here is the documentation <a href="https://www.npmjs.com/package/nodemailer">link</a>.</p><h3>Conclusion</h3><p>Incorporating these packages into your projects can help you tackle various backend challenges:</p><ul><li><strong>node-cron</strong> for scheduling tasks without relying on OS-level CRON jobs.</li><li><strong>multer</strong> for managing file uploads in a user-friendly way.</li><li><strong>socket.io</strong> for enabling real-time communication and making your app more interactive.</li><li><strong>morgan</strong> for logging requests, which is invaluable for debugging and monitoring.</li><li><strong>nodemailer</strong> for sending emails to users directly from your Node.js app.</li></ul><p>Whether you’re building a simple API or a full-fledged web application, these packages can greatly enhance your development workflow and improve the user experience. Try experimenting with each one to see how they fit into your project, and you’ll soon discover the added power and flexibility they bring to your applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ab5cffa55e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I fetch data from google sheets using Node.js ?]]></title>
            <link>https://towardsdev.com/how-i-fetch-data-from-google-sheets-using-node-js-f9fd4efc5bf5?source=rss-b99eba57bf3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9fd4efc5bf5</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[google-sheets]]></category>
            <dc:creator><![CDATA[Code Meets Culture]]></dc:creator>
            <pubDate>Mon, 28 Oct 2024 15:38:23 GMT</pubDate>
            <atom:updated>2024-10-28T15:38:23.513Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I fetch data from google sheets using Node.js ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2VfbINdj6JHQev9G_dOfbA.png" /><figcaption>Google sheet</figcaption></figure><p>You can find the code I used in this tutorial <a href="https://github.com/Pritam1136/fetch-googles-sheet-data">here</a>. But I’ll suggest you to go through the tutorial otherwise it will be extremely difficult to understand the code.</p><h3>Step 1 — Go to console.cloud.google.com</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oqLrkgjy0TSfT3Jow9TAGQ.png" /></figure><p>Next, create a new project by selecting the option on the right side of the modal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rUB1eY1H2CsG155hkaKGsg.png" /></figure><p>Simply enter the project name and click “Done.” Once completed, you’ll see a screen like this; navigate to APIs &amp; Services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDlZEhIT5SAm_zI6Mpzb8Q.png" /></figure><p>Then search for Google Sheet API and then click on that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mCr2a3_EjMmaa4jQxB7Lyg.png" /></figure><p>Now enable the google sheet api.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpHk_YnTYaCXEiIRwp3xwA.png" /></figure><p>After enabling the google sheet api go to credential in API &amp; services and then click on CREATE CREDENTIALS .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJxsNyNQ5ZbZWKr-tdVZaA.png" /></figure><p>In this tutorial we will fetch the google sheet data using Service account but you can explore other options too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1rvoDyicaozqr48a9etSvA.png" /></figure><p>Enter name of your service account and then enter done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aKwNDFuI9TtXSfQc1qMIdg.png" /></figure><p>Now you can see your new service account, we will have to create keys for that service account, so click on that service account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qnqGzGa9Olp5TGotEnOTzQ.png" /></figure><p>Go to the option, keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xTG10MzCeNK2UaaaFUvqCw.png" /></figure><p>Click on ADD KEY and then click on Create new key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CA2q7s_jVVa5zoZc1dHdfg.png" /></figure><p>It is asking on how you will like to download your keys. Click on JSON format. After that a file will get downloaded open that file and go to chat GPT and ask chat GPT to convert that JSON to .env file and we will soon understand why or you can do it manually too if you want to.</p><p>And that’s it all the job of our google cloud console is done. But wait a minute copy your service account email before closing the google cloud console we will need it on our google sheet.</p><h3>Step 2 — Go to google sheet</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jcip6IJ4LPNqP_NHzdRNeA.png" /></figure><p>Let’s create a blank spreadsheet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lGG6fPnFlJ9qnOrJNIEoHg.png" /></figure><p>Let’s rename the untitled sheet to something like Sheet Example and add some data to display on the frontend. Remember the sheet name — here, it’s Sheet1. After entering the data, click Share in the top-right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*1O4C2k5HSmx2L-KSPh7Ygw.png" /></figure><p>After clicking the Share button, enter your service account email, uncheck the Notify people box, and then click Share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0IMKBCwcond9PKbn3F5j1w.png" /></figure><p>That’s it with google sheet, but before closing google sheet copy this google sheet ID. We will know why.</p><h3>Step 3 — Create new Project and open your project on VS code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*gBYNR8jCG5l9QrbHHKp86g.png" /></figure><p>In my new project, I set up two folders: client and server. In the client folder, I created a Vite project using React with a JavaScript configuration, while in the server folder, I initialized a new Express project.</p><pre>{<br>  &quot;name&quot;: &quot;server&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,<br>    &quot;start&quot;: &quot;nodemon index.js&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;cors&quot;: &quot;^2.8.5&quot;,<br>    &quot;dotenv&quot;: &quot;^16.4.5&quot;,<br>    &quot;express&quot;: &quot;^4.21.1&quot;,<br>    &quot;googleapis&quot;: &quot;^144.0.0&quot;,<br>    &quot;nodemon&quot;: &quot;^3.1.7&quot;<br>  }<br>}</pre><p>This are the dependencies I am using on my server you can install the same.</p><pre>const express = require(&quot;express&quot;);<br>const { getSpreadSheetValues } = require(&quot;./googleSheetServices&quot;);<br>const dotenv = require(&quot;dotenv&quot;);<br>const cors = require(&quot;cors&quot;);<br><br>dotenv.config();<br><br>const app = express();<br>app.use(cors());<br><br>app.get(&quot;/api/sheet-data&quot;, async (req, res) =&gt; {<br>  const emploreeData = await getSpreadSheetValues({<br>    spreadsheetId: process.env.SHEET_URL,<br>    sheetName: &quot;Sheet1&quot;,<br>  });<br>  res.send(emploreeData.slice(1));<br>});<br><br>app.listen(5000, () =&gt; {<br>  console.log(&quot;server started&quot;);<br>});</pre><p>Here’s my index.js file, where I’ve set up a basic Express server. The <strong>getSpreadSheetValues</strong> function is where the core functionality occurs. Use your spreadsheetID from the sheet URL you copied, along with the sheet name — Sheet1 in this case.</p><pre>const { google } = require(&quot;googleapis&quot;);<br>const sheets = google.sheets(&quot;v4&quot;);<br>const dotenv = require(&quot;dotenv&quot;);<br><br>dotenv.config();<br><br>async function getAuthToken() {<br>  const auth = new google.auth.GoogleAuth({<br>    credentials: {<br>      type: process.env.TYPE,<br>      project_id: process.env.PROJECT_ID,<br>      private_key_id: process.env.PRIVATE_KEY_ID,<br>      private_key: process.env.PRIVATE_KEY.replace(/\\n/g, &quot;\n&quot;),<br>      client_email: process.env.CLIENT_EMAIL,<br>      client_id: process.env.CLIENT_ID,<br>      auth_uri: process.env.AUTH_URI,<br>      token_uri: process.env.TOKEN_URI,<br>      auth_provider_x509_cert_url: process.env.AUTH_PROVIDER_X509_CERT_URL,<br>      client_x509_cert_url: process.env.CLIENT_X509_CERT_URL,<br>    },<br>    scopes: [&quot;https://www.googleapis.com/auth/spreadsheets.readonly&quot;],<br>  });<br>  return await auth.getClient();<br>}<br><br>async function getSpreadSheetValues({ spreadsheetId, sheetName }) {<br>  try {<br>    const auth = await getAuthToken();<br>    const response = sheets.spreadsheets.values.get({<br>      spreadsheetId,<br>      range: sheetName,<br>      auth,<br>    });<br>    return response.data.values;<br>  } catch (error) {<br>    console.error(&quot;Error fetching data:&quot;, error);<br>    throw new Error(&quot;Error fetching data&quot;);<br>  }<br>}<br><br>module.exports = { getSpreadSheetValues };</pre><p>Remember, I told you to convert that JSON to .env here is why it is needed, we can’t paste those keys directly here we will have to put that values to .env file and we will import those on this files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*jxJAEoRsH8bvqW_ryiejAA.png" /></figure><p>Here’s an example of what my env file looks like for reference. I’ve removed my credentials, which is why I’m sharing it here, but avoid sharing yours in any public project. For the full code of my frontend and backend, check out my <a href="https://github.com/Pritam1136/fetch-googles-sheet-data">GitHub</a>. If you found this tutorial helpful, please consider following me and leaving a like — it really motivates me. It took about 2–3 hours to complete everything from start to finish.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9fd4efc5bf5" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/how-i-fetch-data-from-google-sheets-using-node-js-f9fd4efc5bf5">How I fetch data from google sheets using Node.js ?</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Send Emails Using Node.js: A Beginner’s Guide]]></title>
            <link>https://medium.com/@pritamroy1136/how-to-send-emails-using-node-js-a-beginners-guide-56ce49e47fc5?source=rss-b99eba57bf3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/56ce49e47fc5</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[otp-verification]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Code Meets Culture]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 07:51:06 GMT</pubDate>
            <atom:updated>2024-10-28T05:58:20.669Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I Send OTP Emails Using Node.js: A Beginner’s Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AIKsDukS6BAJ1WFO" /><figcaption>Photo by <a href="https://unsplash.com/@solenfeyissa?utm_source=medium&amp;utm_medium=referral">Solen Feyissa</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In today’s digital world, email verification is an essential feature for ensuring secure user access. A common approach is sending a one-time password (OTP) via email for identity confirmation. In this blog post, I’ll walk you through <strong>step-by-step</strong> how to send OTP emails using <strong>Node.js</strong> and how to verify them.</p><p>Whether you’re a beginner or an experienced developer, this post will guide you through the process of:</p><ul><li>Setting up your Gmail account to allow your application to send emails securely.</li><li>Configuring a Node.js server with Express.</li><li>Using <strong>Nodemailer</strong> to send emails.</li><li>Building an OTP verification system using JWT (JSON Web Token).</li></ul><p>By the end of this guide, you’ll know how to set up an entire OTP-based email verification system from scratch. So, let’s dive right in!</p><p><strong>Feel free to explore the complete code at the end of this blog, and if you find it helpful, don’t forget to give the GitHub repository a star!</strong></p><h4>Step 1: Setup Gmail App Passwords</h4><ol><li><strong>Log into your Gmail account</strong> and navigate to Google Account Security.</li><li><strong>Enable 2-Step Verification</strong> if you haven’t done so already.</li><li>Under the “Signing in to Google” section, you will see an option for <strong>App Passwords</strong>. Click on it(If you don&#39;t find it you can search for it on <strong>“Search google Account”</strong>).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*biZcSBwcFrRVIDicw1nTWg.png" /><figcaption>search for app passwords</figcaption></figure><p><strong>4. Generate an App Password</strong>:</p><ul><li>Enter your app name.</li><li>Copy the generated 16-character password. You will use this in the code.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJW8O4mBxAlhBrYwCGTcbw.png" /><figcaption>I have since deleted this app, which is why I’m sharing it with you now.</figcaption></figure><p>This step allows Node.js to send emails via your Gmail account securely.</p><h4>Step 2: Setup Your Node.js Server</h4><p><strong>Install Required Packages</strong>: First, let’s initialize the Node.js project and install necessary packages.</p><pre>npm init -y<br>npm install express cors nodemailer dotenv jsonwebtoken</pre><p>Create server.js:</p><pre>const express = require(&quot;express&quot;);<br>const cors = require(&quot;cors&quot;);<br>const { sendOtp, verifyOtp } = require(&quot;./Handler&quot;);<br><br>const port = 5000;<br>const app = express();<br>app.use(express.json());<br>app.use(cors());<br><br>app.post(&quot;/api/send-otp&quot;, sendOtp);<br>app.post(&quot;/api/verify-otp&quot;, verifyOtp);<br><br>app.listen(port, () =&gt; {<br>  console.log(`Server running on port ${port}`);<br>});</pre><p>This code sets up a basic Express server that listens on port 5000. We define two routes: one for sending the OTP and another for verifying it.</p><h4>Step 3: Create the Email Sending Logic</h4><p>Create Handler.js:</p><pre>// Import required packages<br>const nodemailer = require(&quot;nodemailer&quot;); // For sending emails<br>const jwt = require(&quot;jsonwebtoken&quot;); // For generating JSON Web Tokens<br>const dotenv = require(&quot;dotenv&quot;); // For loading environment variables<br><br>// Load environment variables from .env file<br>dotenv.config();<br><br>// Retrieve secret key from environment variables<br>const secretKey = process.env.SECRET;<br><br>// In-memory store for OTPs associated with user emails<br>let otpStore = {};<br><br>// Function to send OTP to the user&#39;s email<br>const sendOtp = (req, res) =&gt; {<br>  const { email } = req.body; // Extract email from request body<br><br>  // Check if email is provided<br>  if (!email) {<br>    return res.status(404).json({ message: &quot;User not found&quot; }); // Return error if email is missing<br>  }<br><br>  // Generate a 6-digit OTP<br>  const otp = Math.floor(100000 + Math.random() * 900000);<br>  otpStore[email] = otp; // Store the OTP in otpStore with the associated email<br><br>  // Create transporter for nodemailer<br>  const transporter = nodemailer.createTransport({<br>    service: &quot;Gmail&quot;, // Email service being used<br>    host: &quot;smtp.gmail.com&quot;, // SMTP host<br>    port: 587, // Port for secure email transmission<br>    secure: false, // Use TLS<br>    auth: {<br>      user: process.env.EMAIL_USERNAME, // Email username from environment variables<br>      pass: process.env.EMAIL_PASSWORD, // Email password from environment variables<br>    },<br>  });<br><br>  // Define email options<br>  const mailOptions = {<br>    from: process.env.EMAIL_USERNAME, // Sender&#39;s email<br>    to: email, // Recipient&#39;s email<br>    subject: &quot;Your OTP Code&quot;, // Email subject<br>    html: `<br>      &lt;h1&gt;OTP Verification&lt;/h1&gt;<br>      &lt;p&gt;Your OTP code is &lt;strong&gt;${otp}&lt;/strong&gt;.&lt;/p&gt;<br>      &lt;p&gt;Please use this code to verify your account.&lt;/p&gt;<br>      &lt;p&gt;If you did not request this OTP, please ignore this email.&lt;/p&gt;<br>    `, // HTML content of the email<br>  };<br><br>  // Send email<br>  transporter.sendMail(mailOptions, (error, info) =&gt; {<br>    if (error) {<br>      return res.status(500).json({ message: &quot;Error sending OTP&quot; }); // Return error if sending fails<br>    }<br>    res.status(200).json({ message: `OTP sent to ${email}`, info }); // Return success message<br><br>    // Clear OTP from otpStore after 10 minutes<br>    setTimeout(() =&gt; {<br>      delete otpStore[email]; // Remove the OTP after 10 minutes<br>    }, 600000); // 10 minutes in milliseconds<br>  });<br>};<br><br>// Function to verify OTP<br>const verifyOtp = async (req, res) =&gt; {<br>  const { email, otp } = req.body; // Extract email and OTP from request body<br><br>  // Check if the provided OTP matches the stored OTP<br>  if (otpStore[email] &amp;&amp; otpStore[email] == otp) {<br>    // OTP is correct, generate a JWT token<br>    const token = jwt.sign({ email }, secretKey, {<br>      expiresIn: &quot;1h&quot;, // Set token expiration time to 1 hour<br>    });<br><br>    delete otpStore[email]; // Clear OTP from otpStore after successful verification<br>    return res.status(200).json({ token }); // Return generated token<br>  } else {<br>    return res.status(401).json({ message: &quot;Invalid OTP&quot; }); // Return error for invalid OTP<br>  }<br>};<br><br>// Export the functions for use in other modules<br>module.exports = { sendOtp, verifyOtp };</pre><p>Here, we are using <strong>Nodemailer</strong> to send an OTP to the user’s email and <strong>JWT</strong> to generate a token after OTP verification. The OTP expires after 10 minutes.</p><h4>Step 4: Setup Environment Variables</h4><p>Create a .env file in your root directory and add:</p><pre>EMAIL_USERNAME=your-email@gmail.com<br>EMAIL_PASSWORD=your-app-password<br>SECRET=your-secret-key</pre><p>This keeps sensitive information out of the codebase.</p><h4>Step 5: Frontend Setup (React)</h4><p>I assume that you already know how to setup a react project using vite.</p><p><strong>Install Axios</strong>:</p><pre>npm install axios</pre><p>Create App.jsx:</p><pre>import { useState } from &quot;react&quot;;<br>import axios from &quot;axios&quot;;<br><br>function App() {<br>  const [email, setEmail] = useState(&quot;&quot;);<br>  const [otp, setOtp] = useState(&quot;&quot;);<br>  const [isOtpSent, setIsOtpSent] = useState(false);<br>  const [message, setMessage] = useState(&quot;&quot;);<br><br>  const sendOtp = async () =&gt; {<br>    try {<br>      const response = await axios.post(&quot;http://localhost:5000/api/send-otp&quot;, {<br>        email,<br>      });<br>      setIsOtpSent(true);<br>      setMessage(response.data.message);<br>    } catch (error) {<br>      setMessage(<br>        error.response ? error.response.data.message : &quot;Error sending OTP&quot;<br>      );<br>    }<br>  };<br><br>  const verifyOtp = async () =&gt; {<br>    try {<br>      const response = await axios.post(&quot;http://localhost:5000/api/verify-otp&quot;, {<br>        email,<br>        otp,<br>      });<br>      setMessage(&quot;OTP verified successfully. Token: &quot; + response.data.token);<br>    } catch (error) {<br>      setMessage(error.response ? error.response.data.message : &quot;Invalid OTP&quot;);<br>    }<br>  };<br><br>  return (<br>    &lt;div style={{ textAlign: &quot;center&quot;, marginTop: &quot;50px&quot; }}&gt;<br>      &lt;h1&gt;OTP Verification&lt;/h1&gt;<br><br>      &lt;div&gt;<br>        &lt;label htmlFor=&quot;email&quot;&gt;Email&lt;/label&gt;<br>        &lt;input<br>          type=&quot;email&quot;<br>          id=&quot;email&quot;<br>          name=&quot;email&quot;<br>          placeholder=&quot;Enter your email&quot;<br>          value={email}<br>          onChange={(e) =&gt; setEmail(e.target.value)}<br>        /&gt;<br>        &lt;button onClick={sendOtp}&gt;Send OTP&lt;/button&gt;<br>      &lt;/div&gt;<br><br>      {isOtpSent &amp;&amp; (<br>        &lt;div&gt;<br>          &lt;label htmlFor=&quot;otp&quot;&gt;OTP&lt;/label&gt;<br>          &lt;input<br>            type=&quot;text&quot;<br>            id=&quot;otp&quot;<br>            name=&quot;otp&quot;<br>            placeholder=&quot;Enter OTP&quot;<br>            value={otp}<br>            onChange={(e) =&gt; setOtp(e.target.value)}<br>          /&gt;<br>          &lt;button onClick={verifyOtp}&gt;Verify OTP&lt;/button&gt;<br>        &lt;/div&gt;<br>      )}<br><br>      {message &amp;&amp; &lt;p&gt;{message}&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>This React app allows users to input their email, receive an OTP, and verify it. Axios is used to send requests to the server.</p><h3>Step 6: Running the App</h3><ol><li><strong>Start the Backend</strong>:</li></ol><pre>node server.js</pre><p><strong>2. Run the Frontend</strong>:</p><ul><li>If you’re using Vite React App, run:</li></ul><pre>npm run dev</pre><p>3. Open your browser and go to http://localhost:5173 (assuming React is running on port 5173). Enter your email, click <strong>Send OTP</strong>, check your inbox, and verify the OTP.</p><h3>Conclusion</h3><p>By following this guide, you’ve learned how to send OTPs via email using <strong>Nodemailer</strong> in Node.js, verify the OTPs, and generate JWT tokens upon successful verification. This simple flow is foundational for many real-world applications, such as two-factor authentication.</p><p>Feel free to enhance this setup by adding features like email templates, advanced error handling, or token storage in the frontend. Happy coding!</p><p>GitHub Link — <a href="https://github.com/Pritam1136/nodemailer-example">https://github.com/Pritam1136/nodemailer-example</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56ce49e47fc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>