An application that gets real-time air quality information and allows the user to log in, have an account, and add cities to your profile to have easier access to see that city's air quality. I was inspired to build this application after leaning about how much air quality affects the lives of everyone and everything on earth.
- User authintication
- Password hashing
- Search form for cities air quality
- Ability to save cities to profile
- Ability to update email
- Passport
- Sessions
- BCrypt
- Axios
- Ejs
- Express
- Sequelize
- Postgres
- SQL
Method | Path | Location | Purpose |
---|---|---|---|
GET | / | server.js | Home page |
GET | /auth/login | auth.js | Login form |
GET | /auth/signup | auth.js | Signup form |
POST | /auth/login | auth.js | Login user |
POST | /auth/signup | auth.js | Creates User |
GET | /auth/logout | auth.js | Removes session info |
PUT | /update | server.js | Updates email info |
GET | /profile | server.js | Regular User Profile |
POST | /profile | server.js | Adds city to databse |
DELETE | /profile | server.js | Deletes city from databse |
GET | /airquality | airquality.js | Search page |
GET | /airquality/location | airquality.js | Results from search |
Column Name | Data Type | Notes |
---|---|---|
id | Integer | Serial Primary Key, Auto-generated |
name | String | Must be provided |
String | Must be unique / used for login | |
password | String | Stored as a hash |
createdAt | Date | Auto-generated |
updatedAt | Date | Auto-generated |
Column Name | Data Type | Notes |
---|---|---|
id | Integer | Serial Primary Key, Auto-generated |
name | String | City that was typed into search |
state | String | State that was typed into search |
userId | Integer | Associated with the users id in user model |
createdAt | Date | Auto-generated |
updatedAt | Date | Auto-generated |
airRouter.get("/location", (req, res) => {
const citystate = req.query.location;
const state = req.query.state;
axios
.get(
`https://api.weatherbit.io/v2.0/current/airquality?city=${citystate},${state}&key=${process.env.AIR_API_KEY}`
)
.then((response) => {
const air = response.data;
res.render("airquality", { query: air });
})
.catch((error) => {
console.log(error);
});
});
profileRouter.post("/", (req, res) => {
const { city_name } = req.body;
const state = req.body.state_code;
db.city
.create({
name: city_name,
state: state,
userId: req.user.id,
})
.then(() => {
res.redirect("/profile");
})
.catch((error) => {
console.log(error);
});
});
profileRouter.get("/", (req, res) => {
db.city
.findAll({
where: { userId: req.user.id },
})
.then((city) => {
const cities = city.map((item) => {
return item.dataValues;
});
res.render("profile", { cities });
});
});
app.put("/update", (req, res) => {
db.user
.update(
{
email: req.body.email,
},
{
where: { id: req.user.id },
}
)
.then(() => {
res.redirect("/profile");
});
});
profileRouter.delete("/", (req, res) => {
const { id } = req.body;
db.city
.findOne({
where: { id: id },
})
.then((foundCity) => {
foundCity.destroy().then(() => {
res.redirect("/profile");
});
});
});
https://github.com/JaxonNarramore/suncreen-or-no-sunscreen
npm install
(Or just npm i
for short)
- SESSION_SECRET: Can be any random string; usually a hash in production
- PORT: Usually 3000 or 8000
- AIR-API_KEY: Must get an API key from Weatherbit.io
- COOKIE_KEY: Can be any random string; usually a hash in production
nodemon
or
node index.js
Email: jaxon_narramore@hotmail.com