Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,191,839 members, 7,945,692 topics. Date: Wednesday, 11 September 2024 at 12:17 AM

Created And Deployed My First Express Js Website. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Created And Deployed My First Express Js Website. (616 Views)

Created And Deployed My First Django Website. / I Just Deployed My First App / Just Deployed My App (2) (3) (4)

(1) (Reply) (Go Down)

Created And Deployed My First Express Js Website. by downbad(m): 5:40pm On Jun 15
I have been documenting my progress here as a web developer, as my post history would show.

Almost Two months ago (50 days ago to be exact) I deployed my second ever personal web project that i built with Django. the link to the post is here - https://www.nairaland.com/8074343/created-deployed-second-django-website

I stated that I would be trying my hands with Express js next. Well, here I am.

The link to the website is here - https://express-books-ixez.onrender.com

This project includes functionalities such as profile photo uploads, secure password changes, and account deletions with validation. It offers an admin interface for managing books, and APIs for comments, reviews, likes, favorite genres, password resets, and OTP verifications. Additional features include a search feature that uses ajax for suggestions based on existing books in the database that match what the user is typing out in the search form in real time.

Users can write, edit, and delete book reviews, with secure authentication and CSRF protection. Additionally, users can add, delete, and manage comments on books, and like or unlike reviews, all with proper validation and error handling to ensure data integrity and security.

I prefer working with Django over Express because Django provides many built-in features, whereas Express requires more in-depth customization. Currently, I'm planning to take a week off from computers to read books and watch movies, while also looking for online tech jobs if I qualify. Please excuse any initial loading delays on the website, as it is hosted on a free plan.

Thank you.

1 Like

Re: Created And Deployed My First Express Js Website. by ovanda(m): 6:34pm On Jun 15
This is just beautiful! Bro i am learning PERN stack and I intend to develop a crud application soon. Abeg, how did you implement that next button at the very end of the website?
Re: Created And Deployed My First Express Js Website. by ovanda(m): 6:39pm On Jun 15
Bros abeg, here's my line, I'd like to get in touch with you
08035442507
Re: Created And Deployed My First Express Js Website. by downbad(m): 6:41pm On Jun 15
ovanda:
This is just beautiful! Bro i am learning PERN stack and I intend to develop a crud application soon. Abeg, how did you implement that next button at the very end of the website?

It's called Pagination.
Re: Created And Deployed My First Express Js Website. by Shomek(m): 7:30pm On Jun 15
Nice one from you bro

1 Like

Re: Created And Deployed My First Express Js Website. by downbad(m): 7:39pm On Jun 15
Shomek:
Nice one from you bro

Thanks
Re: Created And Deployed My First Express Js Website. by jesmond3945: 8:38pm On Jun 15
downbad:


Thanks
nice try embedding a machine learning problem
Re: Created And Deployed My First Express Js Website. by downbad(m): 9:04pm On Jun 15
jesmond3945:
nice try embedding a machine learning problem

What do you mean?
Re: Created And Deployed My First Express Js Website. by jesmond3945: 7:16am On Jun 16
downbad:


What do you mean?
a machine learning model into the web application something like a recommender system or a chat bot
Re: Created And Deployed My First Express Js Website. by downbad(m): 8:19am On Jun 16
jesmond3945:
a machine learning model into the web application something like a recommender system or a chat bot

Alright
Re: Created And Deployed My First Express Js Website. by edicied: 12:56pm On Jun 16
jesmond3945:
a machine learning model into the web application something like a recommender system or a chat bot
that's not machine learning
Re: Created And Deployed My First Express Js Website. by silento(m): 1:05pm On Jun 16
Nice one , this is 2024 the only page that is suppose to load is the homepage , other pages should load without the browser refreshing , it can be done with any stack , nice work and hoping to see more improved and advanced demo in future
Re: Created And Deployed My First Express Js Website. by downbad(m): 2:35pm On Jun 16
silento:
Nice one , this is 2024 the only page that is suppose to load is the homepage , other pages should load without the browser refreshing , it can be done with any stack , nice work and hoping to see more improved and advanced demo in future

You mean Infinite scroll? I'm not a fan of it. Reddit was ruined for me when they took away actual paginations. And lots of websites still use pagination.

Thanks for the positive feedback, much appreciated.
Re: Created And Deployed My First Express Js Website. by jesmond3945: 3:57pm On Jun 16
edicied:
that's not machine learning
he has to incorporate something. Nobody cares about web applications without machine learning nowadays.
Re: Created And Deployed My First Express Js Website. by silento(m): 5:11pm On Jun 16
downbad:


You mean Infinite scroll? I'm not a fan of it. Reddit was ruined for me when they took away actual paginations. And lots of websites still use pagination.

Thanks for the positive feedback, much appreciated.

No u can click on next link without page reloading
Re: Created And Deployed My First Express Js Website. by AfDapone: 6:07pm On Jun 16
silento:


No u can click on next link without page reloading

You can click and go to the next page in pagination without reloading in SPA.
Re: Created And Deployed My First Express Js Website. by silento(m): 6:40pm On Jun 16
AfDapone:


You can click and go to the next page in pagination without reloading in SPA.

Not even spa just a regular paged website
Just good knowledge of js
Re: Created And Deployed My First Express Js Website. by Iambro(m): 7:28am On Jun 17
silento:
Nice one , this is 2024 the only page that is suppose to load is the homepage , other pages should load without the browser refreshing , it can be done with any stack , nice work and hoping to see more improved and advanced demo in future
You're a clown
Re: Created And Deployed My First Express Js Website. by downbad(m): 8:21am On Jun 17
Iambro:

You're a clown

Why would you just insult someone for no reason?
Re: Created And Deployed My First Express Js Website. by silento(m): 2:20pm On Jun 17
Iambro:

You're a clown

Must you insult someone 🤔 is anything wrong with ur brain
Re: Created And Deployed My First Express Js Website. by ovanda(m): 1:27pm On Jun 20
ovanda:
Bros abeg, here's my line, I'd like to get in touch with you
08035442507
Bro,I had wanted to get in touch with you because, being a PERN stack developer,I had a question I would have liked to get clarity on but as you no wan respond make I ask the question here.

It's about authentication with session. You can store session in a mongoose database using the code below:

const MongoStore = require('connect-mongo')(session)

app.use(session(
secret: 'SECRET KEY',
resave: false,
saveUninitialized: true,
store: new MongoStore({
url: 'mongodb://localhost:27017/test-app', //YOUR MONGODB URL
ttl: 14 * 24 * 60 * 60,
autoRemove: 'native'
})
))

Or something similar. You don't need to create tables where it is stored as is the case with Postgresql.

To store a session in a postgresql, the code below is needed:

import genFunc from 'connect-pg-simple';

const PostgresqlStore = genFunc(session);
const sessionStore = new PostgresqlStore({
conString: '<insert-connection-string-here>',
}

app.use(session({
secret: 'secret',
resave: false,
saveUninitialized: false,
cookie: cookieOptions, // define cookieOptions
store: sessionStore
}));

I was able to successfully store a session inside a postgresql, using the code above.

In Setting Up the Database

First, I created a database called express-store-test (the name of the database doesn’t really matter).

Then I added a table called session — express will automatically look for this table for finding the session data. This table has 3 columns, which are:


sid is the session id — this is what cookies reference.
sess: contains the session as a JSON object
expire: contains the expiration timestamp for the current session

My question is this?

Assuming I am developing a crud application, would it have a new database with a different name or is there a way to build on the one I created for session?

If I have to create a new database for my crud application, how do i Link it up with the one for session?

1 Like

Re: Created And Deployed My First Express Js Website. by richebony: 5:27pm On Jun 20
Great work!!!
Re: Created And Deployed My First Express Js Website. by downbad(m): 7:31am On Jun 21
ovanda:

Bro,I had wanted to get in touch with you because, being a PERN stack developer,I had a question I would have liked to get clarity on but as you no wan respond make I ask the question here.

It's about authentication with session. You can store session in a mongoose database using the code below:

const MongoStore = require('connect-mongo')(session)

app.use(session(
secret: 'SECRET KEY',
resave: false,
saveUninitialized: true,
store: new MongoStore({
url: 'mongodb://localhost:27017/test-app', //YOUR MONGODB URL
ttl: 14 * 24 * 60 * 60,
autoRemove: 'native'
})
))

Or something similar. You don't need to create tables where it is stored as is the case with Postgresql.

To store a session in a postgresql, the code below is needed:

import genFunc from 'connect-pg-simple';

const PostgresqlStore = genFunc(session);
const sessionStore = new PostgresqlStore({
conString: '<insert-connection-string-here>',
}

app.use(session({
secret: 'secret',
resave: false,
saveUninitialized: false,
cookie: cookieOptions, // define cookieOptions
store: sessionStore
}));

I was able to successfully store a session inside a postgresql, using the code above.

In Setting Up the Database

First, I created a database called express-store-test (the name of the database doesn’t really matter).

Then I added a table called session — express will automatically look for this table for finding the session data. This table has 3 columns, which are:


sid is the session id — this is what cookies reference.
sess: contains the session as a JSON object
expire: contains the expiration timestamp for the current session

My question is this?

Assuming I am developing a crud application, would it have a new database with a different name or is there a way to build on the one I created for session?

If I have to create a new database for my crud application, how do i Link it up with the one for session?


I'm sorry about that, my Whatsapp is for people I know personally.

Do you use Discord?

Edit: I've never used PostgreSQL. I used MongoDB for this project.
Re: Created And Deployed My First Express Js Website. by downbad(m): 7:31am On Jun 21
richebony:
Great work!!!

Thanks
Re: Created And Deployed My First Express Js Website. by ovanda(m): 3:40pm On Jun 21
downbad:


I'm sorry about that, my Whatsapp is for people I know personally.

Do you use Discord?

Edit: I've never used PostgreSQL. I used MongoDB for this project.

In essence, you no know, you no fit help. Thanks though.
Re: Created And Deployed My First Express Js Website. by downbad(m): 5:26pm On Jun 21
ovanda:


In essence, you no know, you no fit help. Thanks though.

You're welcome
Re: Created And Deployed My First Express Js Website. by ovanda(m): 8:20am On Jun 24
You're welcome [/quote]
Bros I don get am, finally and it's working like a beauty!!

There should be two tables(eg, sessions and users) in one database (e.g., `mydb`).

1. `sessions` - used to store session data
2. `users` - used to store user data

Both tables are stored in the same database, but they serve different purposes. The `sessions` table is used by the `express-session` middleware to store session data, while the `users` table is used to store user data for the CRUD operations.

Having separate tables for sessions and users is a common practice, as it allows you to manage and query the data independently. This also helps to keep the data organized and scalable, especially in larger applications.

Here's a high-level overview of how to use sessions and PostgreSQL in an Express CRUD application:

*Sessions:*

1. Install `express-session` and `pg` packages:
```
npm install express-session pg
```
1. Set up session middleware:
```
const session = require('express-session');
const pgSession = require('connect-pg-simple')(session);

app.use(session({
store: new pgSession({
pool: new pg.Pool(/* your PostgreSQL connection settings */),
tableName: 'sessions'
}),
secret: 'your_secret_key',
resave: false,
saveUninitialized: false,
cookie: { secure: true }
}));
```
*PostgreSQL:*

1. Install `pg` package:
```
npm install pg
```
1. Create a PostgreSQL pool:
```
const { Pool } = require('pg');

const pool = new Pool({
user: 'your_username',
host: 'your_host',
database: 'your_database',
password: 'your_password',
port: 5432
});
```
*CRUD Operations:*

1. Create a router for your CRUD endpoints:
```
const router = express.Router();
```
1. Define CRUD operations using the pool and session:
```
router.get('/users', async (req, res) => {
const result = await pool.query('SELECT * FROM users');
req.session.users = result.rows;
res.send(req.session.users);
});

router.post('/users', async (req, res) => {
const { name, email } = req.body;
const result = await pool.query('INSERT INTO users (name, email) VALUES ($1, $2) RETURNING *', [name, email]);
req.session.user = result.rows[0];
res.send(req.session.user);
});

// ...
```
Re: Created And Deployed My First Express Js Website. by downbad(m): 2:35pm On Jun 24
ovanda:

Bros I don get am, finally and it's working like a beauty!!

Cool

(1) (Reply)

Start Earning Atleast #2,000 Weekly From Your Low Traffic Blog! / Internet Secrets Exposed! Free Onlinevalid Email Generator / Professional Web Developer Needed

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 36
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.