Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
luther wardle
Full Stack JavaScript Techdegree Student 18,029 PointsI am getting {"url":"/ not found"} after submitting the form
here's my express code (sorry I'm doing things a little differently than Andrew). i don't know what I'm doing wrong I have the same data on the get and post routes and the pug template is working fine yet for some reason I am getting a 404 error
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
const bodyParser = require('body-parser');
app.set('view engine', 'pug')
app.set("views", path.join(__dirname, "views"));
app.use(bodyParser.urlencoded({extended:false}))
app.use(express.static(path.join(__dirname, 'views')));
app.use(function(req, res) {
res.status(404).send({url: req.originalUrl + ' not found'}) //the current 404 i'm getting :(
});
///////////////////// the basic home route /////////////////////
app.get("/",(req,res)=>{
res.send("the home url")
});
/////////////////////////////////// the form routes ////////////////////////
app.get("/getweather",(req,res)=>{
res.render("index",{states:[
{
id:"WV",
name:"West Virginia"
},
{
id:"WI",
name:"Wisconsin"
},
{
id:"WY",
name:"Wyoming"
}
]});
});
app.post("/getweather",(req,res)=>{
res.render("index",{states:[
{
id:"WV",
name:"West Virginia"
},
{
id:"WI",
name:"Wisconsin"
},
{
id:"WY",
name:"Wyoming"
}
]});)
});
I'm passing in some variables and mapping them as options for users to choose in a select drop down (that's why I have the US states listed in an array)