Go to the project directory and then follow the below given steps:
- npm --version : for version check
- npm init : for initialisation then press enter through the prompts to get a default initialisation
- npm install express : for installing express js framework for node.
- Run the command
node index.js
- Execute the post url on Postman
localhost:3000/api/login
to get the auth token - Copy the auth token
- Execute the url
localhost:3000/api/posts/
by adding Headers - Key as
Authorization
and Value asBearer<space><copied auth token>
- Once you run this you will get the encriped info in the jwt token
- Install XAMPP and run the Apache and MySQL servers
- Go to the application and click
phpMyAdmin
on thelocalhost/dashboard
- Click on the nodemysql (name of my database) to see and explore the CRUD changes to the database. C - Create R - Read U - Update D - Delete
- Take the free community version mongo db subscription.
- In mongodb website create a project -> create a shared cluster.
- Create a user to enable the database access -> copy the password because it will be usefull later on for you node js code.
- After your cluster is created click on connect for the particular cluster to connect to your application or vscode.
- To connect to your application select the driver and version (Node.js and 4.1 or later) and then copy the connection string and replace the with the above copied password.
- This connection string can be used as a URI in .env to connect to your mongodb database.
- Use
npm init -y
to initalise the backend project - Install the required packages using this command
npm i express mongoose nodemon dotenv express-async-handler
. - Under
package.json
add"dev": "nodemon server.js"
to "scripts - Use
npm run dev
command to run nodemon which automatically refreshes the server every time a file is saved.
npm create vite@latest .
setup up the project framework then selectReact
andjavascript
in the options.- Now install the necessary modules
npm i axios react-router-dom
- Go to the backend folder to start the server using
npm run dev
. - Include the bootstrap link and script links from the website in the
index.html
file to use bootstrap navigation bar. - Now run
npm run dev
on the frontend folder to see your changes on the browser.
If you are getting axios Network error while using post then add app.use(cors());
in the server side code and it will work as expected