<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Suraj Sundar</title>
    <description>The latest articles on DEV Community by Suraj Sundar (@surajsundar).</description>
    <link>https://dev.to/surajsundar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2990096%2F53ebe0f5-5952-4ad9-bdb3-dbe1faf167c6.png</url>
      <title>DEV Community: Suraj Sundar</title>
      <link>https://dev.to/surajsundar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/surajsundar"/>
    <language>en</language>
    <item>
      <title>A Beginner’s Guide to Designing RESTful APIs in Node.js</title>
      <dc:creator>Suraj Sundar</dc:creator>
      <pubDate>Fri, 23 May 2025 16:04:27 +0000</pubDate>
      <link>https://dev.to/surajsundar/a-beginners-guide-to-designing-restful-apis-in-nodejs-1eh4</link>
      <guid>https://dev.to/surajsundar/a-beginners-guide-to-designing-restful-apis-in-nodejs-1eh4</guid>
      <description>&lt;p&gt;Building scalable and maintainable APIs is a vital skill for developers in today’s software ecosystem. If you’re just starting out and wondering how to design backend APIs using Node.js and Express.js, this guide is for you.&lt;/p&gt;

&lt;p&gt;We’ll walk through core concepts, folder structure and the reasoning behind architectural decisions — without overwhelming you with complexity.&lt;br&gt;
🚀 Why Backend API Design Matters&lt;/p&gt;

&lt;p&gt;Well-designed APIs are:&lt;br&gt;
✅ Easy to understand and use&lt;br&gt;
✅ Consistent and predictable&lt;br&gt;
✅ Scalable as your application grows&lt;br&gt;
✅ Simple to test and document&lt;/p&gt;

&lt;p&gt;As beginners, the goal isn’t to build a massive system, but to learn how to structure clean, scalable APIs.&lt;br&gt;
🛠️ Tools We’ll Use&lt;/p&gt;

&lt;p&gt;Node.js — JavaScript runtime&lt;br&gt;
Express.js — Web framework for APIs&lt;br&gt;
Optional (for later scaling):&lt;br&gt;
MongoDB / Postgres — For storing data&lt;br&gt;
🗂️ Recommended Folder Structure&lt;/p&gt;

&lt;p&gt;A clear project structure helps scalability and collaboration.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;backend/&lt;br&gt;
├── controllers/ # Logic for routes&lt;br&gt;
│ └── userController.js&lt;br&gt;
├── routes/ # API route definitions&lt;br&gt;
│ └── userRoutes.js&lt;br&gt;
├── app.js # Main server file&lt;br&gt;
└── package.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Why this structure?&lt;/p&gt;

&lt;p&gt;Keeping route definitions and business logic in separate files makes your project easier to maintain and scale.&lt;br&gt;
🧩 Why Use Controllers?&lt;/p&gt;

&lt;p&gt;As your project grows, putting all logic inside routes becomes messy.&lt;br&gt;
Separate controllers help organize the logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// controllers/userController.js
export const getUsers = (req, res) =&amp;gt; {
 // logic here
};

export const addUser = (req, res) =&amp;gt; {
 // logic here
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in your route file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from ‘express’;
import { getUsers, addUser } from ‘../controllers/userController.js’;

const router = express.Router();

router.get('/', getUsers);
router.post('/', addUser);

export default router;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ A Typical Beginner-Friendly Flow&lt;/p&gt;

&lt;p&gt;Let’s say we want to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET a list of users&lt;/li&gt;
&lt;li&gt;POST a new user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// routes/userRoutes.js
router.get(‘/’, getUsers);
router.post(‘/’, addUser);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// controllers/userController.js
let users = [{ id: 1, name: ‘Suraj’ }];

// getUsers
export const getUsers = (req, res) =&amp;gt; {
 try {
 res.status(200).json(users);
 } catch {
 res.status(500).json({ message: 'Server error' });
 }
};

// addUser
export const addUser = (req, res) =&amp;gt; {
 try {
 const { name } = req.body;
 const newUser = { id: users.length + 1, name };
 users.push(newUser);
 res.status(201).json({ message: 'User created', user: newUser });
 } catch {
 res.status(500).json({ message: 'Failed to add user' });
 }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🌱 How to Scale This Later?&lt;/p&gt;

&lt;p&gt;✅ Add database support (e.g., MongoDB, PostgreSQL)&lt;br&gt;
✅ Integrate authentication (JWT, OAuth)&lt;br&gt;
✅ Add middleware for validation, logging, etc.&lt;br&gt;
✅ Implement unit testing&lt;br&gt;
✅ Use dotenv for config and secrets&lt;br&gt;
✨ Final Thoughts&lt;/p&gt;

&lt;p&gt;Your first API doesn’t need to be perfect. But with a clean structure, consistent practices, and documentation, you’ll be miles ahead.&lt;br&gt;
Key Takeaways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use controllers for logic&lt;/li&gt;
&lt;li&gt;Follow REST principles&lt;/li&gt;
&lt;li&gt;Document your API&lt;/li&gt;
&lt;li&gt;Keep code organized&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you found this helpful, share it with others or drop a comment! 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Control an Arduino LED with a MERN Web App – A Beginner’s IoT Project</title>
      <dc:creator>Suraj Sundar</dc:creator>
      <pubDate>Sat, 29 Mar 2025 14:29:03 +0000</pubDate>
      <link>https://dev.to/surajsundar/control-an-arduino-led-with-a-mern-web-app-a-beginners-iot-project-4ool</link>
      <guid>https://dev.to/surajsundar/control-an-arduino-led-with-a-mern-web-app-a-beginners-iot-project-4ool</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As a tech enthusiast, I’ve always been fascinated by the power of the Internet of Things (IoT)—the way physical devices can seamlessly interact with the digital world. Recently, while learning the MERN stack, I was eager to explore how IoT can integrate with web technologies.&lt;/p&gt;

&lt;p&gt;In this beginner-friendly project, I’ll walk through connecting an Arduino UNO board to a web app to control an LED remotely. This project demonstrates a two-way communication system:&lt;/p&gt;

&lt;p&gt;✅ The user interacts with a web app to turn an LED on/off.✅ The real-time status of the LED is displayed in the web app for instant feedback.&lt;/p&gt;

&lt;p&gt;Note: At this stage, I’m not using MongoDB (keeping it simple), focusing instead on establishing a basic connection between an IoT device and a web application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔌 Hardware Setup&lt;/strong&gt;&lt;br&gt;
1️⃣ Set Up the Arduino UNO&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect the Arduino UNO to your computer via USB.&lt;/li&gt;
&lt;li&gt;Install and open the Arduino IDE.&lt;/li&gt;
&lt;li&gt;Select the correct port for the Arduino in the Tools → Port section.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2️⃣ Connect the LED to Arduino&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a digital output pin (e.g., Pin 13) to control the LED.&lt;/li&gt;
&lt;li&gt;Connect the longer leg (anode) of the LED to Pin 13.&lt;/li&gt;
&lt;li&gt;Connect the shorter leg (cathode) to GND.&lt;/li&gt;
&lt;li&gt;Use a resistor (330Ω) in series to prevent excess current.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3️⃣ Ensure Proper Power Supply&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Arduino will be powered via USB, so no external power supply is needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🖥️ Software Integration&lt;/strong&gt;&lt;br&gt;
🔹 &lt;em&gt;&lt;strong&gt;Backend Setup (Node.js &amp;amp; Express)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up a Node.js project and install Express to create a simple web server.&lt;/li&gt;
&lt;li&gt;Use the serialport library to communicate with the Arduino via the serial port.&lt;/li&gt;
&lt;li&gt;Define a /led route in the Express server to handle LED control requests.&lt;/li&gt;
&lt;li&gt;The backend sends ON/OFF commands to the Arduino based on user input.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔹 &lt;em&gt;&lt;strong&gt;Upload Arduino Code&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write and upload Arduino code to listen for serial commands (ON/OFF) and control the LED accordingly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔹 &lt;em&gt;&lt;strong&gt;Frontend Setup (React &amp;amp; Axios)&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a simple React app with buttons to turn the LED ON/OFF.&lt;/li&gt;
&lt;li&gt;Use Axios to send POST requests to the backend.&lt;/li&gt;
&lt;li&gt;Display the current LED status in the frontend based on backend responses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📡 &lt;strong&gt;How It Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1️⃣ User clicks ON/OFF button in the web app.&lt;br&gt;
2️⃣ A request is sent to the backend server.&lt;br&gt;
3️⃣ The server sends a command to the Arduino via serial communication.&lt;br&gt;
4️⃣ Arduino receives the command and controls the LED accordingly.&lt;br&gt;
5️⃣ The web app updates the LED status based on the response.&lt;/p&gt;

&lt;p&gt;🎬 &lt;strong&gt;Demo Video &amp;amp; Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;📽  &lt;a href="https://drive.google.com/file/d/1I-1k7pI-v7wuXuIybsLTfEjPpGMiaWKL/view?usp=drive_link" rel="noopener noreferrer"&gt;Demo Video&lt;/a&gt;&lt;br&gt;
💻 &lt;a href="https://github.com/SoorajSundar1505/IoT_MERN_Development-/tree/master/LED_Controller" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;br&gt;
📝 &lt;a href="https://medium.com/@soorajswtester/getting-started-with-iot-arduino-uno-integrated-with-mern-stack-for-two-way-communication-0aa5a7960914" rel="noopener noreferrer"&gt;Medium Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>iot</category>
      <category>mern</category>
      <category>javascript</category>
      <category>arduino</category>
    </item>
  </channel>
</rss>
