Few Notes:
*npm i -g touch-cli. Or simply just create a file manually.*mkdir server this will create a folder called server on your project’s directory. run cd server to change terminal directory to the server folder you created.npm init -y to initialize a package.json file.npm i express pg corsnpm i -g nodemonNodemon is a utility that automatically restarts your server when changes are made to your code. This means that you can make changes to your code and immediately see the effects without having to manually stop and restart the server each time. It is particularly useful during development when you are frequently making changes and testing them.
index.js inside the server folder which also has the previously created package.json the new file is the file entry that is specified in package.json.index.js file, write the following code:const express = require("express");
const app = express();
let PORT = 5000; // or 3001, 5001, 9000, whichever works
app.listen(PORT, () => {
console.log(`Server is listening on Port ${PORT}`);
});
/server directory and run the following command: nodemonServer is listening on Port 5000index.js you now have to include CORS using the following lines of code. Position them appropriately in the index fileWhat the hell is CORS used for? CORS stands for Cross-Origin Resource Sharing. It is a security feature that restricts web pages or web applications from making requests to a different domain or port than the one that served the original resource. In the context of an Express server, CORS is used to allow a request from a client-side application that is running on a different domain or port to access resources from the server. By enabling CORS, you can specify which domains or ports are allowed to access your server's resources. This is important for security reasons as it helps prevent malicious attacks such as Cross-Site Request Forgery (CSRF) and Cross-Site Scripting (XSS).