This project is a full-stack note-taking application built using the MERN stack (MongoDB, Express.js, React.js, Node.js). It allows users to create, view, update, and delete notes. The backend is powered by Node.js and Express, with MongoDB for data storage. The frontend is developed using React.
- Create Notes: Add new notes with a title and content.
- View Notes: View all saved notes.
- Edit Notes: Update existing notes.
- Delete Notes: Remove notes that are no longer needed.
- Backend: Node.js, Express.js, Mongoose
- Frontend: React.js, Axios
- Database: MongoDB (MongoDB Atlas)
note-taking-app/
├── client/
│ ├── public/
│ ├── src/
│ │ ├── components/
│ │ │ ├── NoteList.js
│ │ │ ├── NoteForm.js
│ │ │ ├── NoteItem.js
│ │ ├── App.js
│ ├── package.json
├── server.js
├── models/
│ ├── Note.js
├── routes/
│ ├── notes.js
├── .env
├── package.json
In the root directory, run:
npm install
This will install the following dependencies:
express
: Web framework for Node.jsmongoose
: MongoDB object modeling toolcors
: Middleware for enabling Cross-Origin Resource Sharingdotenv
: Module for loading environment variables
Create a .env
file in the root directory and add your MongoDB connection string:
MONGO_URI=your_mongodb_connection_string
Start the server using nodemon
:
npm run server
The server will run on http://localhost:5000
.
- GET /notes: Retrieve all notes
- POST /notes: Create a new note
- GET /notes/:id: Retrieve a single note by ID
- PUT /notes/:id: Update a note by ID
- DELETE /notes/:id: Delete a note by ID
Navigate to the client
directory and run:
npm install
This will install the following dependencies:
axios
: Promise-based HTTP client for making API requests
Start the React development server:
npm start
The application will run on http://localhost:3000
.
NoteList.js
: Fetches and displays all notes.NoteForm.js
: Form for creating and updating notes.NoteItem.js
: Displays individual notes.
Ensure that App.js
imports the components correctly:
import React, { useState } from 'react';
import NoteList from './components/NoteList';
import NoteForm from './components/NoteForm';
const App = () => {
const [selectedNote, setSelectedNote] = useState(null);
const handleSave = (newNote) => {
setSelectedNote(null);
};
return (
<div>
<h1>Note Taking App</h1>
<NoteForm note={selectedNote} onSave={handleSave} />
<NoteList />
</div>
);
};
export default App;
To create a production-ready build of the frontend, run the following command inside the client
directory:
npm run build
This will generate a build
folder containing static files for the React app.
To deploy the application, you can serve the built files using a static server or deploy them on platforms like Heroku, Vercel, or Netlify.
You can configure your Express server to serve the static files. In server.js
, add the following:
const path = require('path');
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
Now, when you deploy your app, the Express server will serve the React frontend.
If you'd like to contribute to this project, feel free to fork the repository and submit a pull request.
This project is licensed under the MIT License.