<?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>Forem: M Ahsan Hameed</title>
    <description>The latest articles on Forem by M Ahsan Hameed (@ahsanjutt01).</description>
    <link>https://forem.com/ahsanjutt01</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%2F667877%2Fb419d2dc-ef46-40d2-b84a-cba6c178f9e8.jpeg</url>
      <title>Forem: M Ahsan Hameed</title>
      <link>https://forem.com/ahsanjutt01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ahsanjutt01"/>
    <language>en</language>
    <item>
      <title>Building a Scalable Node.Js Backend: Sequelize Models, CRUD Operations &amp; Clean Architecture</title>
      <dc:creator>M Ahsan Hameed</dc:creator>
      <pubDate>Wed, 04 Jun 2025 19:58:25 +0000</pubDate>
      <link>https://forem.com/ahsanjutt01/building-a-scalable-nodejs-backend-sequelize-models-crud-operations-clean-architecture-59k6</link>
      <guid>https://forem.com/ahsanjutt01/building-a-scalable-nodejs-backend-sequelize-models-crud-operations-clean-architecture-59k6</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;a href="https://dev.to/ahsanjutt01/how-to-set-up-a-nodejs-express-app-with-sequelize-and-aws-mysql-rds-source-code-28kj"&gt;How to Set Up a Node.js Express App with Sequelize and AWS MySQL RDS + Source Code&lt;/a&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Two Ways to Get Started:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;1️⃣ Follow the step-by-step guide in the tutorial above.&lt;br&gt;
2️⃣ Download the source code and practice at your own pace.&lt;/p&gt;

&lt;p&gt;🚀 An exciting journey awaits—let’s begin!&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this post, we will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define Sequelize models for User and Post tables.&lt;/li&gt;
&lt;li&gt;Set up the routes, controllers, and services to handle CRUD operations.&lt;/li&gt;
&lt;li&gt;Maintain a clean and scalable code structure by separating concerns into different folders.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s dive in and organize our code to make it more maintainable!&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Define Sequelize Models (Tables)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sequelize models represent the structure of the database tables. Let’s start by defining the models for User and Post.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;1.1. Create the User Model&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In the models folder, create a file named User.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/models/User.js
const { DataTypes } = require('sequelize');
const sequelize = require('../db');

const User = sequelize.define('User', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  username: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  email: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
  },
});

module.exports = User;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This model defines the User table with id, username, and email fields.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1.2. Create the Post Model&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Next, create a Post.js file in the models folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/models/Post.js
const { DataTypes } = require('sequelize');
const sequelize = require('../db');
const User = require('./User');  // Reference to User model

const Post = sequelize.define('Post', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  title: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: false,
  },
});

// Define relationship: One User has many Posts
Post.belongsTo(User, { foreignKey: 'userId' });

module.exports = Post;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This defines the Post model with title, content, and a relationship to the User model.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Create Routes, Controllers, and Services&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To maintain clean and scalable code, we will separate the application logic into routes, controllers, and services.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2.1. Folder Structure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s organize the folders as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/src
  /controllers
    userController.js
    postController.js
  /routes
    userRoutes.js
    postRoutes.js
  /services
    userService.js
    postService.js
  /models
    User.js
    Post.js
  app.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;2.2. Create Services for Business Logic&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The service layer will handle the actual business logic, such as interacting with the database.&lt;/p&gt;

&lt;p&gt;userService.js&lt;br&gt;
Create the services/userService.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// services/userService.js
const User = require('../models/User');

const createUser = async (username, email) =&amp;gt; {
  const user = await User.create({ username, email });
  return user;
};

const getAllUsers = async () =&amp;gt; {
  const users = await User.findAll();
  return users;
};

const getUserById = async (id) =&amp;gt; {
  const user = await User.findByPk(id);
  return user;
};

const updateUser = async (id, username, email) =&amp;gt; {
  const user = await User.findByPk(id);
  if (user) {
    user.username = username;
    user.email = email;
    await user.save();
    return user;
  }
  return null;
};

const deleteUser = async (id) =&amp;gt; {
  const user = await User.findByPk(id);
  if (user) {
    await user.destroy();
    return true;
  }
  return false;
};

module.exports = {
  createUser,
  getAllUsers,
  getUserById,
  updateUser,
  deleteUser,
};
postService.js
Create the services/postService.js file:

javascript
Copy
// services/postService.js
const Post = require('../models/Post');

const createPost = async (title, content, userId) =&amp;gt; {
  const post = await Post.create({ title, content, userId });
  return post;
};

const getAllPosts = async () =&amp;gt; {
  const posts = await Post.findAll();
  return posts;
};

const getPostById = async (id) =&amp;gt; {
  const post = await Post.findByPk(id);
  return post;
};

const updatePost = async (id, title, content) =&amp;gt; {
  const post = await Post.findByPk(id);
  if (post) {
    post.title = title;
    post.content = content;
    await post.save();
    return post;
  }
  return null;
};

const deletePost = async (id) =&amp;gt; {
  const post = await Post.findByPk(id);
  if (post) {
    await post.destroy();
    return true;
  }
  return false;
};

module.exports = {
  createPost,
  getAllPosts,
  getPostById,
  updatePost,
  deletePost,
};
2.3. Create Controllers for Handling Requests
The controller layer will handle HTTP requests and interact with the services.

userController.js
Create the controllers/userController.js file:

javascript
Copy
// controllers/userController.js
const userService = require('../services/userService');

const createUser = async (req, res) =&amp;gt; {
  const { username, email } = req.body;
  try {
    const user = await userService.createUser(username, email);
    res.status(201).json(user);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

const getAllUsers = async (req, res) =&amp;gt; {
  try {
    const users = await userService.getAllUsers();
    res.status(200).json(users);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

const updateUser = async (req, res) =&amp;gt; {
  const { id } = req.params;
  const { username, email } = req.body;
  try {
    const user = await userService.updateUser(id, username, email);
    if (user) {
      res.status(200).json(user);
    } else {
      res.status(404).json({ message: 'User not found' });
    }
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

const deleteUser = async (req, res) =&amp;gt; {
  const { id } = req.params;
  try {
    const success = await userService.deleteUser(id);
    if (success) {
      res.status(200).json({ message: 'User deleted' });
    } else {
      res.status(404).json({ message: 'User not found' });
    }
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

module.exports = {
  createUser,
  getAllUsers,
  updateUser,
  deleteUser,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;postController.js&lt;br&gt;
Create the controllers/postController.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// controllers/postController.js
const postService = require('../services/postService');

const createPost = async (req, res) =&amp;gt; {
  const { title, content, userId } = req.body;
  try {
    const post = await postService.createPost(title, content, userId);
    res.status(201).json(post);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

const getAllPosts = async (req, res) =&amp;gt; {
  try {
    const posts = await postService.getAllPosts();
    res.status(200).json(posts);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

const updatePost = async (req, res) =&amp;gt; {
  const { id } = req.params;
  const { title, content } = req.body;
  try {
    const post = await postService.updatePost(id, title, content);
    if (post) {
      res.status(200).json(post);
    } else {
      res.status(404).json({ message: 'Post not found' });
    }
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

const deletePost = async (req, res) =&amp;gt; {
  const { id } = req.params;
  try {
    const success = await postService.deletePost(id);
    if (success) {
      res.status(200).json({ message: 'Post deleted' });
    } else {
      res.status(404).json({ message: 'Post not found' });
    }
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

module.exports = {
  createPost,
  getAllPosts,
  updatePost,
  deletePost,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;2.4. Create Routes for the API&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now, let's define the routes to connect the controllers to our app.&lt;/p&gt;

&lt;p&gt;userRoutes.js&lt;br&gt;
Create the routes/userRoutes.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// routes/userRoutes.js
const express = require('express');
const userController = require('../controllers/userController');
const router = express.Router();

router.post('/users', userController.createUser);
router.get('/users', userController.getAllUsers);
router.put('/users/:id', userController.updateUser);
router.delete('/users/:id', userController.deleteUser);

module.exports = router;
postRoutes.js
Create the routes/postRoutes.js file:

javascript
Copy
// routes/postRoutes.js
const express = require('express');
const postController = require('../controllers/postController');
const router = express.Router();

router.post('/posts', postController.createPost);
router.get('/posts', postController.getAllPosts);
router.put('/posts/:id', postController.updatePost);
router.delete('/posts/:id', postController.deletePost);

module.exports = router;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Set Up Express Application and Routes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Finally, let’s bring everything together in the app.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js
const express = require('express');
const sequelize = require('./db');
const userRoutes = require('./routes/userRoutes');
const postRoutes = require('./routes/postRoutes');

const app = express();
const port = 3000;

app.use(express.json());
app.use(userRoutes);
app.use(postRoutes);

sequelize.authenticate().then(() =&amp;gt; {
  console.log('Database connected successfully!');
}).catch((error) =&amp;gt; {
  console.error('Unable to connect to the database:', error);
});

sequelize.sync({ force: true }).then(() =&amp;gt; {
  console.log('Database synced');
});

app.listen(port, () =&amp;gt; {
  console.log(`App running at http://localhost:${port}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Test Your CRUD Endpoints&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now that we’ve defined the models and set up CRUD operations, let’s test everything using Postman or cURL:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;POST /users: Create a new user.&lt;/li&gt;
&lt;li&gt;GET /users: Get all users.&lt;/li&gt;
&lt;li&gt;PUT /users/🆔 Update a user by id.&lt;/li&gt;
&lt;li&gt;DELETE /users/🆔 Delete a user by id.&lt;/li&gt;
&lt;li&gt;POST /posts: Create a new post.&lt;/li&gt;
&lt;li&gt;GET /posts: Get all posts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/ahsanjutt01/node-express-mysql/tree/crud" rel="noopener noreferrer"&gt;DOWNLOAD SOURCE CODE 'crud' BRANCH&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this post, we’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Defined Sequelize models for User and Post.&lt;/li&gt;
&lt;li&gt;Created routes, controllers, and services to handle CRUD operations.&lt;/li&gt;
&lt;li&gt;Structured the code into separate folders for routes, controllers, and services to maintain a clean and scalable architecture.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the next post, we’ll explore authentication, authorization, and deployment.&lt;/p&gt;

</description>
      <category>node</category>
      <category>sequelize</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to Set Up a Node.js Express App with Sequelize and AWS MySQL RDS + Source Code</title>
      <dc:creator>M Ahsan Hameed</dc:creator>
      <pubDate>Mon, 02 Jun 2025 00:20:00 +0000</pubDate>
      <link>https://forem.com/ahsanjutt01/how-to-set-up-a-nodejs-express-app-with-sequelize-and-aws-mysql-rds-source-code-28kj</link>
      <guid>https://forem.com/ahsanjutt01/how-to-set-up-a-nodejs-express-app-with-sequelize-and-aws-mysql-rds-source-code-28kj</guid>
      <description>&lt;h2&gt;
  
  
  Let's Start
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this post, we will start our journey of building a Node.js application using &lt;strong&gt;Express&lt;/strong&gt; and &lt;strong&gt;Sequelize ORM&lt;/strong&gt;, while connecting it to an &lt;strong&gt;AWS MySQL RDS (Free Tier)&lt;/strong&gt; database. By the end of this post, we’ll have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A basic Node.js Express app.&lt;/li&gt;
&lt;li&gt;A connection to a MySQL database hosted on AWS RDS.&lt;/li&gt;
&lt;li&gt;A working environment with Sequelize ORM to interact with the database.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s dive into it!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Step 1: Setting Up Your Node.js Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1.1. Install Node.js&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before we begin, make sure you have Node.js installed. If you don’t have it yet, download it from the official website: &lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;Node.js Download&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1.2. Initialize a New Node.js Project&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now, let's create a directory for our project and initialize it with npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir node-express-mysql
cd node-express-mysql
npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The -y flag automatically accepts the default settings for your package.json file.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1.3. Install Required Dependencies&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, let’s install the necessary libraries for our project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;express: A minimalist web framework for Node.js.&lt;/li&gt;
&lt;li&gt;sequelize: An ORM for interacting with the database.&lt;/li&gt;
&lt;li&gt;mysql2: MySQL client for Sequelize.&lt;/li&gt;
&lt;li&gt;dotenv: For managing environment variables securely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run the following command to install these dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express sequelize mysql2 dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 2: Set Up Your AWS MySQL RDS Database&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2.1. Create a MySQL RDS Instance&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Log in to your AWS Management Console.&lt;/li&gt;
&lt;li&gt;Go to RDS and click Create database.&lt;/li&gt;
&lt;li&gt;Choose MySQL as the database engine.&lt;/li&gt;
&lt;li&gt;For DB Instance Identifier, set a name for your database (e.g., my-mysql-db).&lt;/li&gt;
&lt;li&gt;Set Master Username and Master Password.&lt;/li&gt;
&lt;li&gt;Under Settings, choose the Free Tier option for cost-saving.&lt;/li&gt;
&lt;li&gt;Set up the VPC security group to allow inbound traffic from your IP address (make sure you can access it remotely).&lt;/li&gt;
&lt;li&gt;Note down the Endpoint, Master Username, and Password once the instance is ready.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2.2. Configure Security Group&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;After creating your RDS instance, configure the VPC Security Group to allow inbound connections from your local IP. This step ensures that you can access the database from your Node.js application.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 3: Set Up Sequelize to Connect to MySQL&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3.1. Create a .env File&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We will use the dotenv package to securely store our database credentials. Create a .env file in the root of your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_HOST=your-mysql-db-instance-name.rds.amazonaws.com
DB_USER=admin
DB_PASSWORD=yourpassword
DB_NAME=yourdbname
DB_DIALECT=mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the values with your actual database details.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3.2. Sequelize Configuration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Create a file called db.js for configuring the Sequelize connection to your MySQL database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// db.js
require('dotenv').config();
const { Sequelize } = require('sequelize');

// Set up Sequelize connection
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
  host: process.env.DB_HOST,
  dialect: process.env.DB_DIALECT,
});

module.exports = sequelize;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file will use the environment variables from the .env file to establish a connection to the MySQL database.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 4: Create Your Express Application&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4.1. Set Up the Basic Express App&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now let’s create a basic Express app in app.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app.js
const express = require('express');
const sequelize = require('./db');
require('dotenv').config();

const app = express();
const port = 3000;

app.use(express.json());

// Test DB Connection
sequelize.authenticate()
  .then(() =&amp;gt; console.log('Database connected successfully!'))
  .catch((error) =&amp;gt; console.error('Unable to connect to the database:', error));

app.listen(port, () =&amp;gt; {
  console.log(`App running at http://localhost:${port}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;4.2. Test Database Connection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In the above code:&lt;/p&gt;

&lt;p&gt;We initialize Express and set it up to listen on port 3000.&lt;/p&gt;

&lt;p&gt;We use Sequelize's authenticate method to verify if we can successfully connect to the MySQL database.&lt;/p&gt;

&lt;p&gt;If the connection is successful, we’ll see "Database connected successfully!" in the terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4.3. Run the Application&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Start the application by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node app.js
You should see:
&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;App running at http://localhost:3000
Database connected successfully!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see "Database connected successfully!", it means your connection to the MySQL database hosted on AWS RDS is working!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ahsanjutt01/node-express-mysql/tree/post-1-setup" rel="noopener noreferrer"&gt;DOWNLOAD SOURCE CODE&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this first post of our learning journey, we’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up a Node.js Express application.&lt;/li&gt;
&lt;li&gt;Connected it to a MySQL RDS database using Sequelize ORM.&lt;/li&gt;
&lt;li&gt;Tested the connection to ensure everything is working smoothly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the next post, we’ll move on to creating Sequelize models, define our database tables, and perform basic &lt;strong&gt;&lt;em&gt;CRUD operations&lt;/em&gt;&lt;/strong&gt; (Create, Read, Update, Delete).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Next Post Preview&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We will define Sequelize models (tables) for our app.&lt;/li&gt;
&lt;li&gt;We’ll dive into CRUD operations using Sequelize.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stay tuned for the next post, and feel free to drop any questions or feedback below!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>node</category>
      <category>aws</category>
      <category>rds</category>
    </item>
    <item>
      <title>Build A Hello World API With Node.js And Express.Js + Postman</title>
      <dc:creator>M Ahsan Hameed</dc:creator>
      <pubDate>Sun, 04 Sep 2022 02:06:48 +0000</pubDate>
      <link>https://forem.com/ahsanjutt01/build-a-hello-world-api-with-nodejs-and-expressjs-postman-4com</link>
      <guid>https://forem.com/ahsanjutt01/build-a-hello-world-api-with-nodejs-and-expressjs-postman-4com</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Getting Started&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To get started create a new folder on any directory and call it hello_world.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ mkdir hello_world&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To move to that folder use this command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ cd hello_world&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In your hello_world folder create a new file called app.js&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ touch app.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The next step for us to do is to install Node. You can install node &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We are close to create the app.&lt;/p&gt;

&lt;p&gt;After node has been installed then we’ll install express with npm. Node comes with npm so we won’t need to install npm.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Click the return key repeatedly for every questions asked of you on the command line.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Install Dependencies&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;npm install express —-save&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setup The App And Create Our First Endpoint&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now let’s get started creating our &lt;code&gt;hello_world&lt;/code&gt; API in the app.js file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const express = require('express');&lt;br&gt;
const app = express();&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setting Server Port&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Add more code in our app.js file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const port =8000;&lt;br&gt;
app.listen(port,()=&amp;gt; {&lt;br&gt;
console.log(&lt;/code&gt;Server is listening on port ${port}&lt;code&gt;);&lt;br&gt;
})&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Create API&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's start writing code for our first API.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app.get('/hello_world', (req, res)=&amp;gt;{&lt;br&gt;
res.send('Hello World');&lt;br&gt;
})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;get shows the HTTP GET &lt;br&gt;
First parameter is our API path&lt;br&gt;
Second parameter a callback function&lt;br&gt;
Callback function first request shorthand req&lt;br&gt;
Callback function first response shorthand res&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Start Server&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Hurrah...! We are just created the server with hello world API next step is pretty easy to start the server run that command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ npm start&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Check postman&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmwo2b2b9u7m10q86i6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwmwo2b2b9u7m10q86i6o.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pretty Easy Congrats you tested it....?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Follow For more update and stay connected&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw96a48b4wgf7nnu5zfll.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw96a48b4wgf7nnu5zfll.gif" alt="Image description" width="500" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
