From 5e1976f919fdd24e6f112a6c28756af8bc0cbc8d Mon Sep 17 00:00:00 2001 From: ProPy2023 <144798650+ProPy2023@users.noreply.github.com> Date: Thu, 4 Apr 2024 19:17:35 +0530 Subject: [PATCH 1/7] Update README.md --- README.md | 91 +------------------------------------------------------ 1 file changed, 1 insertion(+), 90 deletions(-) diff --git a/README.md b/README.md index 15fb6d7..39c0849 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # Node.js Express, Sequelize & PostgreSQL: CRUD Rest APIs -For instruction, please visit: -> [Node.js CRUD Rest APIs with Express, Sequelize & PostgreSQL example](https://bezkoder.com/node-express-sequelize-postgresql/) - We will build Rest Apis that can create, retrieve, update, delete and find Tutorials by title. The following table shows overview of the Rest APIs that will be exported: @@ -16,19 +13,7 @@ The following table shows overview of the Rest APIs that will be exported: - GET `api/tutorials/published` find all published Tutorials - GET `api/tutorials?title=[kw]` find all Tutorials which title contains 'kw' -Front-end that works well with this Back-end -> [Axios Client](https://www.bezkoder.com/axios-request/) - -> [Angular 8](https://www.bezkoder.com/angular-crud-app/) / [Angular 10](https://www.bezkoder.com/angular-10-crud-app/) / [Angular 11](https://www.bezkoder.com/angular-11-crud-app/) / [Angular 12](https://www.bezkoder.com/angular-12-crud-app/) / [Angular 13](https://www.bezkoder.com/angular-13-crud-example/) / [Angular 14](https://www.bezkoder.com/angular-14-crud-example/) / [Angular 15](https://www.bezkoder.com/angular-15-crud-example/) / [Angular 16](https://www.bezkoder.com/angular-16-crud-example/) / [Angular 17](https://www.bezkoder.com/angular-17-crud-example/) - -> [Vue 2 Client](https://www.bezkoder.com/vue-js-crud-app/) / [Vue 3 Client](https://www.bezkoder.com/vue-3-crud/) / [Vuetify Client](https://www.bezkoder.com/vuetify-data-table-example/) - -> [React Client](https://www.bezkoder.com/react-crud-web-api/) / [React Redux Client](https://www.bezkoder.com/react-redux-crud-example/) -## Demo Video -This is our Node.js PostgreSQL CRUD example using Express & Sequelize application demo, test Rest Apis with Postman. - -[![Node.js PostgreSQL CRUD example Github](http://img.youtube.com/vi/x1pZHN_sjGk/0.jpg)](http://www.youtube.com/watch?v=x1pZHN_sjGk "Node.js PostgreSQL CRUD example Github") ### Test the APIs Run our Node.js application with command: `node server.js`. @@ -37,18 +22,6 @@ Using Postman, we're gonna test all the Apis above. - Create a new Tutorial using `POST /tutorials` Api -![node-js-postgresql-crud-example-create](https://dev-to-uploads.s3.amazonaws.com/i/hqvz8ra9p21z927iwzph.png) - -After creating some new Tutorials, you can check PostgreSQL table: -```testdb=# select * from tutorials; - id | title | description | published | createdAt | updatedAt -----+-------------+-------------------+-----------+----------------------------+---------------------------- - 1 | Node Tut #1 | Tut#1 Description | f | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07 - 2 | Node Tut #2 | Tut#2 Description | f | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:43:05.131+07 - 3 | Node Tut #3 | Tut#3 Description | f | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07 - 4 | Js Tut #4 | Tut#4 Desc | f | 2020-01-29 10:45:40.016+07 | 2020-01-29 10:45:40.016+07 - 5 | Js Tut #5 | Tut#5 Desc | f | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:45:44.289+07 -``` - Retrieve all Tutorials using `GET /tutorials` Api @@ -62,16 +35,6 @@ After creating some new Tutorials, you can check PostgreSQL table: ![node-js-postgresql-crud-example-update](https://dev-to-uploads.s3.amazonaws.com/i/3buqfz0by0lu2z4kf3uq.png) -Check `tutorials` table after some rows were updated: -```testdb=# select * from tutorials; - id | title | description | published | createdAt | updatedAt -----+----------------+-------------------+-----------+----------------------------+---------------------------- - 1 | Node Tut #1 | Tut#1 Description | f | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07 - 3 | Node Tut #3 | Tut#3 Description | f | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07 - 2 | Node Js Tut #2 | Tut#2 Description | t | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:51:55.235+07 - 4 | Js Tut #4 | Tut#4 Desc | t | 2020-01-29 10:45:40.016+07 | 2020-01-29 10:54:17.468+07 - 5 | Js Tut #5 | Tut#5 Desc | t | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:54:20.544+07 -``` - Find all Tutorials which title contains 'js': `GET /tutorials?title=js` @@ -85,15 +48,7 @@ Check `tutorials` table after some rows were updated: ![node-js-postgresql-crud-example-delete-one](https://dev-to-uploads.s3.amazonaws.com/i/pyos3wq4tchb8ixuyj1c.png) -Tutorial with id=4 was removed from `tutorials` table: -```testdb=# select * from tutorials; - id | title | description | published | createdAt | updatedAt -----+----------------+-------------------+-----------+----------------------------+---------------------------- - 1 | Node Tut #1 | Tut#1 Description | f | 2020-01-29 10:42:57.121+07 | 2020-01-29 10:42:57.121+07 - 3 | Node Tut #3 | Tut#3 Description | f | 2020-01-29 10:43:48.028+07 | 2020-01-29 10:43:48.028+07 - 2 | Node Js Tut #2 | Tut#2 Description | t | 2020-01-29 10:43:05.131+07 | 2020-01-29 10:51:55.235+07 - 5 | Js Tut #5 | Tut#5 Desc | t | 2020-01-29 10:45:44.289+07 | 2020-01-29 10:54:20.544+07 -``` + - Delete all Tutorials using `DELETE /tutorials` Api @@ -105,50 +60,6 @@ Now there are no rows in `tutorials` table: ----+-------+-------------+-----------+-----------+----------- ``` -More Practice: -> [Node.js Express Pagination with PostgreSQL example](https://bezkoder.com/node-js-pagination-postgresql/) - -> [Node.js Express File Upload Rest API example](https://bezkoder.com/node-js-express-file-upload/) - -> [Node.js Express File Upload with Google Cloud Storage example](https://bezkoder.com/google-cloud-storage-nodejs-upload-file/) - -Security: -> [Node.js JWT Authentication & Authorization with PostgreSQL example](https://bezkoder.com/node-js-jwt-authentication-postgresql/) - -Associations: -> [Sequelize Associations: One-to-Many Relationship example](https://bezkoder.com/sequelize-associate-one-to-many/) - -> [Sequelize Associations: Many-to-Many Relationship example](https://bezkoder.com/sequelize-associate-many-to-many/) - -Fullstack: -> [Vue + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/vue-node-express-postgresql/) - -> [React + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/react-node-express-postgresql/) - -> [Angular 8 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-node-express-postgresql/) - -> [Angular 10 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-10-node-express-postgresql/) - -> [Angular 11 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-11-node-js-express-postgresql/) - -> [Angular 12 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-12-node-js-express-postgresql/) - -> [Angular 13 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-13-node-js-express-postgresql/) - -> [Angular 14 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-14-node-js-express-postgresql/) - -> [Angular 15 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-15-node-js-express-postgresql/) - -> [Angular 16 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-16-node-js-express-postgresql/) - -> [Angular 17 + Node.js + Express + PostgreSQL example](https://www.bezkoder.com/angular-17-node-js-express-postgresql/) - -Integration (run back-end & front-end on same server/port) -> [Integrate React with Node.js Restful Services](https://bezkoder.com/integrate-react-express-same-server-port/) - -> [Integrate Angular with Node.js Restful Services](https://bezkoder.com/integrate-angular-10-node-js/) - -> [Integrate Vue with Node.js Restful Services](https://bezkoder.com/serve-vue-app-express/) ## Project setup ``` From 8cc65accddf33820c92b59155ac87366be44b62d Mon Sep 17 00:00:00 2001 From: ProPy2023 <144798650+ProPy2023@users.noreply.github.com> Date: Thu, 4 Apr 2024 19:21:52 +0530 Subject: [PATCH 2/7] Delete README.md --- README.md | 72 ------------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 39c0849..0000000 --- a/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# Node.js Express, Sequelize & PostgreSQL: CRUD Rest APIs - -We will build Rest Apis that can create, retrieve, update, delete and find Tutorials by title. - -The following table shows overview of the Rest APIs that will be exported: - -- GET `api/tutorials` get all Tutorials -- GET `api/tutorials/:id` get Tutorial by id -- POST `api/tutorials` add new Tutorial -- PUT `api/tutorials/:id` update Tutorial by id -- DELETE `api/tutorials/:id` remove Tutorial by id -- DELETE `api/tutorials` remove all Tutorials -- GET `api/tutorials/published` find all published Tutorials -- GET `api/tutorials?title=[kw]` find all Tutorials which title contains 'kw' - - - -### Test the APIs -Run our Node.js application with command: `node server.js`. - -Using Postman, we're gonna test all the Apis above. - -- Create a new Tutorial using `POST /tutorials` Api - - -- Retrieve all Tutorials using `GET /tutorials` Api - -![node-js-postgresql-crud-example-retrieve-all](https://dev-to-uploads.s3.amazonaws.com/i/m9razjm1njgww58er3as.png) - -- Retrieve a single Tutorial by id using `GET /tutorials/:id` Api - -![node-js-postgresql-crud-example-retrieve-one](https://dev-to-uploads.s3.amazonaws.com/i/0kuojvc596i5u423od2b.png) - -- Update a Tutorial using `PUT /tutorials/:id` Api - -![node-js-postgresql-crud-example-update](https://dev-to-uploads.s3.amazonaws.com/i/3buqfz0by0lu2z4kf3uq.png) - - -- Find all Tutorials which title contains 'js': `GET /tutorials?title=js` - -![node-js-postgresql-crud-example-search](https://dev-to-uploads.s3.amazonaws.com/i/u2hbmz5r35o7uo09y3z5.png) - -- Find all published Tutorials using `GET /tutorials/published` Api - -![node-js-postgresql-crud-example-search-status](https://dev-to-uploads.s3.amazonaws.com/i/dbo753wfqibt0b93d82d.png) - -- Delete a Tutorial using `DELETE /tutorials/:id` Api - -![node-js-postgresql-crud-example-delete-one](https://dev-to-uploads.s3.amazonaws.com/i/pyos3wq4tchb8ixuyj1c.png) - - - -- Delete all Tutorials using `DELETE /tutorials` Api - -![node-js-postgresql-crud-example-delete-all](https://dev-to-uploads.s3.amazonaws.com/i/ga42747jorssl20ywyug.png) - -Now there are no rows in `tutorials` table: -```testdb=# select * from tutorials; - id | title | description | published | createdAt | updatedAt -----+-------+-------------+-----------+-----------+----------- -``` - - -## Project setup -``` -npm install -``` - -### Run -``` -node server.js -``` From 9d5fb467fc8122a06ab5cacce7bb8c56627053e7 Mon Sep 17 00:00:00 2001 From: ProPy2023 <144798650+ProPy2023@users.noreply.github.com> Date: Thu, 4 Apr 2024 20:27:46 +0530 Subject: [PATCH 3/7] Update db.config.js --- app/config/db.config.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/config/db.config.js b/app/config/db.config.js index 64ba9c5..6b1a925 100644 --- a/app/config/db.config.js +++ b/app/config/db.config.js @@ -1,4 +1,4 @@ -module.exports = { +/*module.exports = { HOST: "localhost", USER: "postgres", PASSWORD: "123", @@ -11,3 +11,26 @@ module.exports = { idle: 10000 } }; +*/ + +module.exports = { + HOST: "dpg-co7bpEn109ks73860js0-a.oregon-postgres.render.com", + USER: "postgres_user", + PASSWORD: "J4lg1IhBM7viuX8EH6PnUKx8Q9U8xECm", + DB: "testdb_vnej", + dialect: "postgres", + dialectOptions: { + ssl: { + require: true, + rejectUnauthorized: false // Allow self-signed certificates + }, + keepAlive: true + }, + ssl: true, + pool: { + max: 5, + min: 0, + acquire: 30000, + idle: 10000 + } +}; From 620db29f5927ecce906ec49068931caed1a14534 Mon Sep 17 00:00:00 2001 From: ProPy2023 <144798650+ProPy2023@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:09:15 +0530 Subject: [PATCH 4/7] Update db.config.js --- app/config/db.config.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/config/db.config.js b/app/config/db.config.js index 6b1a925..8ac667c 100644 --- a/app/config/db.config.js +++ b/app/config/db.config.js @@ -20,10 +20,7 @@ module.exports = { DB: "testdb_vnej", dialect: "postgres", dialectOptions: { - ssl: { - require: true, - rejectUnauthorized: false // Allow self-signed certificates - }, + "ssl": true , keepAlive: true }, ssl: true, From c4caa229a4c13bc005afb55380896f0744acdf35 Mon Sep 17 00:00:00 2001 From: ProPy2023 <144798650+ProPy2023@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:26:34 +0530 Subject: [PATCH 5/7] Update index.js --- app/models/index.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/app/models/index.js b/app/models/index.js index 02c3c9e..e9d39b7 100644 --- a/app/models/index.js +++ b/app/models/index.js @@ -1,15 +1,27 @@ const dbConfig = require("../config/db.config.js"); const Sequelize = require("sequelize"); -const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, { - host: dbConfig.HOST, - dialect: dbConfig.dialect, - - pool: { - max: dbConfig.pool.max, - min: dbConfig.pool.min, - acquire: dbConfig.pool.acquire, - idle: dbConfig.pool.idle +// const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, { +// host: dbConfig.HOST, +// dialect: dbConfig.dialect, + +// pool: { +// max: dbConfig.pool.max, +// min: dbConfig.pool.min, +// acquire: dbConfig.pool.acquire, +// idle: dbConfig.pool.idle +// } +// }); + + +// Connection string +const connectionString = 'postgres://postgres_user:J4lg1IhAM7viuX8EH6PnUKx8Q9U8xECm@dpg-co7bp0n109ks73860js0-a.oregon-postgres.render.com/testdb_vnej'; + +// Initialize Sequelize with the connection string +const sequelize = new Sequelize(connectionString, { + dialect: 'postgres', // Specify the dialect + dialectOptions: { + ssl: true // Enable SSL } }); From a425679fdfcd79e96144813d3ed2ccac1c168d14 Mon Sep 17 00:00:00 2001 From: ProPy2023 <144798650+ProPy2023@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:06:57 +0530 Subject: [PATCH 6/7] Update server.js createdby --- server.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server.js b/server.js index 7565472..de0053a 100644 --- a/server.js +++ b/server.js @@ -16,6 +16,10 @@ app.use(express.json()); /* bodyParser.json() is deprecated */ // parse requests of content-type - application/x-www-form-urlencoded app.use(express.urlencoded({ extended: true })); /* bodyParser.urlencoded() is deprecated */ +app.get("/createdBy",(req,res)=>{ + res.send("Name of the Student : Patel jaykumar vijaybhai \n Enrollment No : SR22MSIT015 \n Technology : NodeJs \n Organization : Maruti Techno Lab") +}); + const db = require("./app/models"); db.sequelize.sync(); // // drop the table if it already exists From 131e015cd5f16357f10c780908b4d6158ba0593f Mon Sep 17 00:00:00 2001 From: ProPy2023 <144798650+ProPy2023@users.noreply.github.com> Date: Sat, 8 Jun 2024 16:12:51 +0530 Subject: [PATCH 7/7] Update server.js --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index de0053a..5b35b0a 100644 --- a/server.js +++ b/server.js @@ -29,7 +29,7 @@ db.sequelize.sync(); // simple route app.get("/", (req, res) => { - res.json({ message: "Welcome to bezkoder application." }); + res.json({ message: "Welcome to my application." }); }); require("./app/routes/turorial.routes")(app);