In this video, we will build a Full Stack Travel Story App using the MERN stack (MongoDB, Express, React, Node.js). This app allows users to sign up, log in, and create personal travel stories with features like image uploads, and adding travel date. We also implement search functionality to find stories, filter by date range, and pin favorite stories to the top. Users can also edit or delete their stories..
The backend features secure JWT authentication, MongoDB for storing user data and travel stories, and APIs for adding, editing, deleting stories, and uploading images. This tutorial covers the entire development process, from setting up the frontend and backend to integrating APIs and building the UI components.
使用教程
git clone 整个项目
添加.env配置信息
cd backend 先执行npm install再执行npm start
cd frontend 先执行npm install再执行npm run dev
默认打开http://localhost:5173
TimeStamps
Frontend React Project Setup
00:00 - Demo of Travel Story App
04:50 - Frontend React app setup
执行如下指令:
1
2
3
4
5
mkdir TravelStory
cd TravelStory
mkdir frontend
mkdir backend
cd frontend
added 85 packages in 7s
125 packages are looking for funding
run `npm fund` for details
Created Tailwind CSS config file: tailwind.config.js
Created PostCSS config file: postcss.config.js
Configure your template paths
Add the paths to all of your template files in your tailwind.config.js file.
/** @type {import('tailwindcss').Config} */exportdefault{content:["./index.html","./src/**/*.{js,ts,jsx,tsx}",],theme:{fontFamily:{display:["Poppins","sans-serif"],},extend:{// Colors used in the project
colors:{primary:"#05B6D3",secondary:"#EF863E",}},},plugins:[],}
11:33 - react-router-dom installation & setup
执行npm i react-route-dom
Backend
14:32 - Backend Node.js Express project setup
在backend目录下执行npm init -y
输出信息如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Wrote to /home/xxxxxxxx/TravelStory/backend/package.json:
{
"name": "travelstory",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
在backend目录下执行npm i express mongoose jsonwebtoken dotenv cors nodemon bcrypt
constbcrypt=require("bcrypt");constexpress=require("express");constcors=require("cors");constjwt=require("jsonwebtoken");constapp=express();app.use(express.json());app.use(cors({origin:"*"}));//Test api
app.post("/hello",async(req,res)=>{returnres.status(200).json({message:"hello"});})app.listen(8000);module.exports=app;
Error connecting to MongoDB Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist: https://www.mongodb.com/docs/atlas/security-whitelist/
cd backend
xxxxxxxx@DESKTOP-393QBO3:~/TravelStory/backend$ npm i multer
added 16 packages in 3s
23 packages are looking for funding
run `npm fund` for details
This was what was in my Postman Settings. But in my Desktop, the folder was names as Postman Agent, so the path was ~/Postman Agent/files. Therefore Postman couldn’t read from my system, rename Postman Agent in your local machine to Postman.
This is more like a bug with Postman (already open issue, still not corrected).
/** @type {import('tailwindcss').Config} */exportdefault{content:["./index.html","./src/**/*.{js,ts,jsx,tsx}",],theme:{fontFamily:{display:["Poppins","sans-serif"],},extend:{// Colors used in the project
colors:{primary:"#05B6D3",secondary:"#EF863E",},backgroundImage:{'login-bg-img':"url('./src/assets/images/bg-image.png')",'signup-bg-img':"url('./src/assets/images/signup-bg-image.jpg')",}},},plugins:[],}
Short summary: bcrypt is a native (C++) module, thus much faster than bcryptjs which is a pure js module.
bcrypt sometimes requires additional steps to build correctly, especially if you are using architectures other than x86_64 or a glibc based distro. You will need additional dependencies to compile from source.
bcryptjs is plain js, hence works everywhere, even browsers. bcrypt runs only on NodeJS, Node-WebKit or Electron.
Picsvg is a free online converter that can convert an image to a SVG file.You can upload an image file (jpg,gif,png) up to 4 Mb, then you can select effects to enhance the SVG image result.