<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged personal-blog</title>
<link>https://coderlegion.com/tag/personal-blog</link>
<description>Powered by Question2Answer</description>
<item>
<title>Build a Personal Blog with Node.js and Express</title>
<link>https://coderlegion.com/11904/build-a-personal-blog-with-node-js-and-express</link>
<description>&lt;p&gt;Creating a personal blog is a great way to share your thoughts, ideas, and projects with the world. In this tutorial, we'll walk through building and deploying a blog application using Node.js and Express.&lt;/p&gt;
&lt;h3 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;
&lt;p&gt;Before starting, ensure you have the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Node.js installed on your machine&lt;/li&gt;
&lt;li&gt;Basic understanding of JavaScript&lt;/li&gt;
&lt;li&gt;A code editor (like VS Code)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;step-1-set-up-your-project&quot;&gt;Step 1: Set Up Your Project&lt;/h3&gt;
&lt;p&gt;Open your terminal and create a new directory for your blog. Navigate to it and initialize a new Node.js project:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;mkdir my-personal-blog
cd my-personal-blog
npm init -y
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This creates a &lt;code&gt;package.json&lt;/code&gt; file, where all your project dependencies will reside.&lt;/p&gt;
&lt;h3 id=&quot;step-2-install-necessary-packages&quot;&gt;Step 2: Install Necessary Packages&lt;/h3&gt;
&lt;p&gt;Next, you’ll need to install Express and some other helpful packages:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install express body-parser ejs mongoose dotenv
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;express&lt;/strong&gt; handles your server logic.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;body-parser&lt;/strong&gt; helps parse incoming request bodies.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ejs&lt;/strong&gt; is a templating engine for rendering HTML.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;mongoose&lt;/strong&gt; interacts with MongoDB for data management.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;dotenv&lt;/strong&gt; manages environment variables.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;step-3-set-up-your-server&quot;&gt;Step 3: Set Up Your Server&lt;/h3&gt;
&lt;p&gt;Create a new file called &lt;code&gt;server.js&lt;/code&gt; and set up a basic Express server:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const app = express();
const PORT = process.env.PORT || 5000;

mongoose.connect('mongodb://localhost/my-blog', { useNewUrlParser: true, useUnifiedTopology: true });

app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs');

app.get('/', (req, res) =&amp;gt; {
  res.send('Welcome to My Personal Blog');
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server is running on port ${PORT}`);
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This simple setup initiates an Express server that listens for requests.&lt;/p&gt;
&lt;h3 id=&quot;step-4-define-your-database-schema&quot;&gt;Step 4: Define Your Database Schema&lt;/h3&gt;
&lt;p&gt;Create a folder named &lt;code&gt;models&lt;/code&gt; and add a file named &lt;code&gt;Post.js&lt;/code&gt; for your blog posts schema:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;const mongoose = require('mongoose');

const postSchema = new mongoose.Schema({
  title: String,
  content: String,
  createdAt: { type: Date, default: Date.now }
});

module.exports = mongoose.model('Post', postSchema);
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-5-create-blog-routes&quot;&gt;Step 5: Create Blog Routes&lt;/h3&gt;
&lt;p&gt;Add routes to create and display posts. In your &lt;code&gt;server.js&lt;/code&gt;, include the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;const Post = require('./models/Post'); 

app.get('/posts', async (req, res) =&amp;gt; {
  const posts = await Post.find();
  res.render('posts', { posts });
});

app.post('/posts', async (req, res) =&amp;gt; {
  const newPost = new Post({ title: req.body.title, content: req.body.content });
  await newPost.save();
  res.redirect('/posts');
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-6-create-views&quot;&gt;Step 6: Create Views&lt;/h3&gt;
&lt;p&gt;Create a &lt;code&gt;views&lt;/code&gt; folder, and within it create &lt;code&gt;posts.ejs&lt;/code&gt; which renders your posts:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;My Blog&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;h1&amp;gt;My Blog Posts&amp;lt;/h1&amp;gt;
  &amp;lt;form action=&quot;/posts&quot; method=&quot;POST&quot;&amp;gt;
    &amp;lt;input type=&quot;text&quot; name=&quot;title&quot; placeholder=&quot;Title&quot; required&amp;gt;
    &amp;lt;textarea name=&quot;content&quot; placeholder=&quot;Content&quot; required&amp;gt;&amp;lt;/textarea&amp;gt;
    &amp;lt;button type=&quot;submit&quot;&amp;gt;Add Post&amp;lt;/button&amp;gt;
  &amp;lt;/form&amp;gt;
  &amp;lt;ul&amp;gt;
    &amp;lt;% posts.forEach(post =&amp;gt; { %&amp;gt;
      &amp;lt;li&amp;gt;&amp;lt;h2&amp;gt;&amp;lt;%= post.title %&amp;gt;&amp;lt;/h2&amp;gt;&amp;lt;p&amp;gt;&amp;lt;%= post.content %&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;% }) %&amp;gt;
  &amp;lt;/ul&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-7-test-your-application&quot;&gt;Step 7: Test Your Application&lt;/h3&gt;
&lt;p&gt;Start your server:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;node server.js
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Open your browser and navigate to &lt;code&gt;http://localhost:5000&lt;/code&gt;. You should see your personal blog!&lt;/p&gt;
&lt;h3 id=&quot;step-8-deploy-your-blog&quot;&gt;Step 8: Deploy Your Blog&lt;/h3&gt;
&lt;p&gt;Now that your blog is up and running, consider deploying it using platforms like Heroku or Vercel. Follow their guides on how to deploy Node.js applications.&lt;/p&gt;
&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Congratulations! You’ve built and deployed a personal blog using Node.js and Express. This project sets a solid foundation for exploring more advanced features like user authentication, comments, or even media uploads in the future. Happy coding!&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/11904/build-a-personal-blog-with-node-js-and-express</guid>
<pubDate>Thu, 19 Feb 2026 08:29:45 +0000</pubDate>
</item>
</channel>
</rss>