My #100DaysOfCode Journey: Building "Mindful Melanin"

Akia YoungAkia Young
3 min read

It has been a gratifying experience thus far diving back into coding and revamping my developer portfolio for my #100DaysOfCode challenge. Over the past weekend, on days 3 and 4, I embarked on an exciting learning journey focused on MongoDB and Express JS. My goal is to build a full-stack app called "Mindful Melanin", an affirmation app designed specifically for Black Women on their mindfulness and well-being journey. This app will include a space for journaling, a space for goal tracking, and of course, a space where daily affirmations are served. Keep reading as I share the highlights of my progress and the things I've learned along the way.

Day 3: Creating the Backend Structure

On day 3 I delved into the creation of the backend directory and files. This involved setting up the essential components for the server side of "Mindful Melanin". I created three crucial files: server.js, routes.js, and models.js. Let's take a closer look at the code snippets from this phase:

// server.js
const express = require('express');
const app = express();
const cors = require('cors');
const bodyParser = require('body-parser');

// Set up middleware
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// Define routes
app.use('/api', require('./routes'));

// Start the server
const port = 3000;
app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

First, I went ahead and established the backbone of my backend infrastructure. In the server.js file, I set up the Express.js server and configured middleware such as cors and body-parser to handle cross-origin resource sharing and request data parsing.

// routes.js
const express = require('express');
const router = express.Router();

// Import models here
const JournalEntry = require('./models/JournalEntry');
const Goal = require('./models/Goal');
const Affirmation = require('./models/Affirmation');

// Define the routes here
// ...

module.exports = router;

The routes.js file laid the foundation for defining the API routes, while the models.js file connects to the MongoDB Database in models.js as pictured below.

// models.js
const mongoose = require('mongoose');

// Start database connection here
const MONGODB_URI = 'mongodb+srv://Cluster52420:<password>@cluster52420.6cb6sgj.mongodb.net/';
mongoose.connect(MONGODB_URI, {
  useNewUrlParser: true,
  useUnifiedTopology: true,   
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
db.once('open', () => {
  console.log('Connected to MongoDB');
});

// Define the models here
// ...

Day 4: Setting up the Express.js Server

Day 4 took me a while to wrap my head around in terms of setting up the server because I noticed that when I started the server the page would load but it would load to a white screen. After resetting my cache and cookies and trying it in both Google Chrome Browser and Firefox, I was able to get it to load. The Express.js server as mentioned before is responsible for the backend functionality. Here is my updated code snippet:

// server.js (continued)
const express = require('express');
const app = express();
const cors = require('cors');
const bodyParser = require('body-parser');

// Set up middleware
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// Define routes
const routes = require('./routes');
app.use(routes);

// Start the server
const port = 3000;
app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

My favorite part about coding is when the code actually works. lol

Today, on day 5, I am enthusiastic about defining the API routes and models which will be essential in connecting the front end to the back end. This step is bringing me closer to the realization of "Mindful Melanin" and its empowering potential and purpose.

Please Stay connected with me on this building journey!

As I continue this journey of Mindfulness while building I would love for you to join me and stay connected. If you also share a passion for programming mindfulness, or. uplifting Black Women, let's support each other and make a positive impact together. Let's code, grow and learn together!

0
Subscribe to my newsletter

Read articles from Akia Young directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Akia Young
Akia Young