← choose a testing method | how-to's | how to do a health-check | dividend tracker api documentation
You only have to test using one method.
There are multiple methods to test the health of the API. See Step 2: Choose a method to test the endpoint
The server must be up and running!
If you haven't already done so, then start your local server.
Step 2: Method 3: Test by creating and running your own script
- Navigate to the root folder where you forked the Dividend Tracker API repo
- Create a file and give it a meaningful name like
test-api-health.js - Paste the code below in the file you've just created and save it.
const axios = require('axios');
(async () => {
try {
const response = await axios.get('http://localhost:3000/');
console.log('Health check successful:', response.data);
} catch (err) {
if (err.response) {
console.error('API responded with error:', err.response.status, err.response.data);
} else {
console.error('Health check failed:', err.message);
}
}
})();
- Run the script by using the command below:
node test-api-health.js
If successful then you will see output similar to below:
node test-api-health.js
Health check successful: { message: 'Hello API!' }