Skip to content

Instantly share code, notes, and snippets.

@duttaANI
Created December 26, 2023 14:26
Show Gist options
  • Save duttaANI/7c0201fc135342b699a7850e5e772590 to your computer and use it in GitHub Desktop.
Save duttaANI/7c0201fc135342b699a7850e5e772590 to your computer and use it in GitHub Desktop.
docker network
// client_server.js
const express = require('express');
const axios = require('axios');
const app = express();
const port = 4000;
app.get('/getdata', async (req, res) => {
try {
// Make a request to the API server using its container name
const apiResponse = await axios.get('http://api_server:3000/api/data');
res.json({ message: apiResponse.data.message });
} catch (error) {
console.error(error.message);
res.status(500).json({ error: 'Internal Server Error' });
}
});
app.listen(port, () => {
console.log(`Client server listening at http://localhost:${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment