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 trialjason limmm
8,009 Pointscookie not being saved
here is my pug
doctype html
html(lang="en")
head
title Flashcards
body
block content
extends boilerplate.pug
block content
if name
h1 Hello, #{name}!
else
form(action="/hello", method="post")
label Please enter your name:
input(type="text" name="username")
button(type="submit") Submit
here is my js code
const express = require('express');
const bodyparser = require('body-parser');
const cookieparser = require('cookie-parser')
const app = express();
app.use(bodyparser.urlencoded({ extended: false}))
app.use(cookieparser());
app.set('view engine', 'pug');
app.listen(3000, ()=>console.log("app.js is now listening to port 3000!"));
app.get("/", (req, res)=>{
res.render('yowassup');
});
app.get("/hello", (req, res)=>{
res.render('hello', { name:req.cookies.username });
});
app.post("/hello", (req, res)=>{
res.render('hello', {name:req.body.username});
});
anything i did wrong in this code when i submitted the form it doesn't save the cookie
1 Answer
Rohald van Merode
Treehouse StaffHey jason limmm 👋
Looking at the HTML form ,you're making a POST request to /hello
, but the route in your JS code is not doing anything with that information other than passing it to the hello
template. You're not actually creating a cookie to store the value in.