Jul 12, 2024
npm init
(use default values)npm install express ejs
npm install --save-dev nodemon dotenv
.env
for environment variables.gitignore
to ignore node_modules
and .env
"scripts": {
"dev": "nodemon server.js"
}
server.js
npm run dev
GET /
: Render homepageviews/index.ejs
login.ejs
register.ejs
POST /login
POST /register
express.urlencoded
bcrypt
: npm install bcrypt
users
arraynpm install passport passport-local express-session express-flash
passport-config.js
POST /login
with passportcheckAuthenticated
for protected routescheckNotAuthenticated
for guest-only routes (e.g., login, register)DELETE /logout
method-override
for form submissions
npm install method-override