This project provides a simple Node.js server demonstrating how to implement Cross-Origin Resource Sharing (CORS). It serves as a foundational example to help developers learn how to configure CORS for handling cross-origin requests in web applications.
- Basic Express.js setup
- Configured CORS middleware to handle requests from different origins
- Development and production mode support
- Easy to extend for adding routes and logic
To run this project, you'll need:
- Clone the repository:
git clone https://github.com/Thinkful-Ed/starter-cors-backend.git
- Navigate into the project directory:
cd starter-cors-backend
- Install the required dependencies:
npm install
- Start the application:
- For a regular run:
npm start
- For development mode with auto-restart:
npm run start:dev
- For a regular run:
The server will run on the default port 5555
, or you can set your preferred port by defining the PORT
environment variable.
Example:
PORT=3000 npm start
starter-cors-backend/
├── src/ # Contains the main application files
│ └── app.js # Main Express application file
├── .gitignore # Specifies files to ignore in version control
├── package.json # Project metadata and dependencies
├── package-lock.json # Version-lock for installed packages
└── README.md # Project documentation
- You can add new API routes by modifying the
src/app.js
file. - To enable CORS for specific domains or HTTP methods, modify the CORS configuration within
app.js
.
CORS (Cross-Origin Resource Sharing) is a mechanism that allows web applications to securely make requests to resources on other domains. This is important for applications that communicate with APIs hosted on a different origin from the front-end application. The cors
middleware in this project is pre-configured for ease of use.