Welcome all!
This is a simple Node.js and Express API designed to serve a globally shared counter for tracking clicks on an element (e.g., a "pet me" image) on a website.
globalPetCounter). This means the count will reset every time the server restarts. For a production environment, you must integrate a proper database (like PostgreSQL, MongoDB, or Redis) to ensure the count is persistent.
Follow these steps to get the server running on your local machine.
You must have Node.js and npm (Node Package Manager) installed on your system.
To check if they are installed, open your terminal and run:
node -v
npm -vInitialize npm: This creates the package.json file.
npm init -yInstall Dependencies: Install the necessary packages: Express for the server framework and CORS to allow your website (on a different domain) to make requests.
npm install express corsRun the server from your terminal:
node server.jsYou should see the message: Server running on http://localhost:3000
The API is now running locally!