https://air-quality-data-app.herokuapp.com/
Designed and implemented an app that allows users to see current air quality in San Francisco Area.
Integrated with AirNow API for displaying most recent data.
Deployed Version:
- AirNow API,
- MongoDB,
- Express,
- Node,
- HTML / CSS,
- Particles.js
Currently in progress:
- AirNow API,
- MongoDB,
- Express,
- React
- Node,
- HTML / CSS,
- Lodash
- Particles.js
- Create server:
- For being able to store my api key I decided to create a server that proxies the request to the original server. I also added a cron like task scheduler for grabbing the recent information and storing it to the database.
- Use upsert: instead of iterating over records and see if a record already exists, I decided to use MongoDB upsert. Method will update a record if already exists, otherwise create a new record.
db.AirQuality.updateOne({ ReportingArea: newDBRecord.ReportingArea }, newDBRecord, { upsert: true }, (err, updatedRecord) => {
if (err) {
return console.log(err);
}
res.status(200).json({ status: 200, message: 'instance created', recordupdatedRecord })
})
- Use node HTTPS module in the standard library: too many external modules increase a chance of bugs. I decided to explore native node methods.
app.get('/link', (req, res) => {
const options = {
//hostname, path and type of the request
};
const request = https.request(options, resp => {
let dataStr = "";
resp.on('data', d => {
//store chunk of data into a string variable
});
resp.on('end', () => {
//create db instance and send status
});
});
request.on('error', error => {
//handle error
});
request.end();
});
Alternative tried - axios.
- Use particles.js: I really liked this lightweight JavaScript library for creating particles. It is a very user friendly library that helps to achieve a great result.
https://air-quality-data-app.herokuapp.com/
- Add more cities.
- Switch to React for reusing the same components.