Skip to content

Instantly share code, notes, and snippets.

View maisonm's full-sized avatar
🌴
On vacation (in my mind)

Maison Moa maisonm

🌴
On vacation (in my mind)
  • Florida
View GitHub Profile
const fs = require('fs');
const path = require('path');
module.exports = (app) => {
fs.readdirSync('routes/api/').forEach((file) => {
require(`./api/${file.substr(0, file.indexOf('.'))}`)(app);
})
}
app.get('/search-location-weather', (req, res) => {
//build api URL with user zip
const baseUrl = 'http://api.openweathermap.org/data/2.5/weather?zip=';
const apiId = '&appid=<YOUR API KEY GOES HERE>&units=imperial';
const userLocation = (url1, url2, zipcode) => {
let newUrl = url1 + zipcode + url2;
return newUrl;
};
let zipcode;
app.post('/search-location', (req, res) => {
zipcode = req.body.zipcode;
if(!zipcode || zipcode.length < 5 || zipcode.length > 5) {
res.redirect('/error');
} else {
res.redirect('/current-weather');
}
const fetch = require('node-fetch');
module.exports = (app) => {
let zipcode;
app.post('/search-location', (req, res) => {
zipcode = req.body.zipcode;
const express = require('express');
const app = express();
const port = 5000;
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.get('/', (req, res) => {
res.send('PORT 5000');
})
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
state = {
data: null
};
componentDidMount() {
const express = require('express');
const app = express();
const port = process.env.PORT || 5000;
// console.log that your server is up and running
app.listen(port, () => console.log(`Listening on port ${port}`));
// create a GET route
app.get('/express_backend', (req, res) => {
res.send({ express: 'YOUR EXPRESS BACKEND IS CONNECTED TO REACT' });
#box1 {
order: 2;
}
#box2{
order: 1;
}
#box3 {
order: 4;
}
#box4{
.container {
display: flex;
flex-wrap: wrap;
background: #1c9dc5;
font-family: 'Rubik', sans-serif;
height: 350px;
width: 400px;
}
.container {
display: flex;
background: #1c9dc5;
font-family: 'Rubik', sans-serif;
}
.box {
border: solid #333 2px;
background: #a8a8a8;
height: 150px;