A small Node.js + Express blog application with server-side rendered views using EJS.
- Create, view, edit, and delete blog posts
- Server-side rendered pages with EJS templates
- Bootstrap-based layout and custom styles
- PostgreSQL storage for posts
index.js- Main Express application entry pointdb.js- PostgreSQL connection pool, schema initialization, and post queries.env.example- PostgreSQL connection settings templatepackage.json- Node dependencies and package metadatapublic/- Static assetsmain.css- Custom stylinglogo-notepad.png- App logo image
views/- EJS view templatesindex.ejs- Landing/home pageapp.ejs- New blog post formpost_new.ejs- List of published postspost_view.ejs- Single post displaypost_edit.ejs- Edit form for an existing postpartials/- Shared componentsheader.ejs- Header with navigationfooter.ejs- Footer content
- Install dependencies from the project directory:
cd "C:\Users\hp\Desktop\Full Stack Web Development\BlogWebApp"
npm install- Create a PostgreSQL database. For a local PostgreSQL installation, run:
CREATE DATABASE blogdb;- Create the environment file:
Copy-Item .env.example .envOpen .env and replace your_password with the password for the PostgreSQL user. The default local connection is:
postgresql://postgres:your_password@localhost:5432/blogdb
You can instead set separate PGHOST, PGPORT, PGDATABASE, PGUSER, and PGPASSWORD values. DATABASE_URL takes precedence when provided.
- Run the application:
npm start- Open your browser at:
http://localhost:3000- Visit
/to view the landing page and saved posts loaded from PostgreSQL. - Visit
/postto create a new blog post. - After posting, you are redirected to
/post/newwhere all posts are listed. - Use the
Viewbutton to open a post at/post/:id. - Use the
Editbutton to modify a post at/post/:id/edit. - Use the
Deletebutton to remove a post.
- On startup,
db.jscreates thepoststable if it does not already exist. Restarting the server does not delete posts. - Post titles are optional; blank titles display as
Untitled. - Post content is required to create or save a post.
- express
- body-parser
- ejs
- pg
- dotenv