Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
unicodeveloper committed Nov 13, 2024
1 parent 40ac99b commit c237d78
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/docs/guides/express.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Afterward, you can access the app at `http://localhost:8080`.

### Add and Configure Database

**Note:** We'll use Postgres. If you don't have it locally, go ahead and install or use a different Node database package.
**Note:** We will be using Postgres for this app. If you dont have it installed locally, you can either [install it](https://www.postgresql.org/download) or use a different Node.js database package of your choice.

1. Create a database named `expresshelloworld_dev`.

Expand Down Expand Up @@ -82,6 +82,12 @@ router.get('/', function(req, res, next) {
module.exports = router;
```

The code above sets up a simple Express app with a route handler for the home page. It uses the `pg-promise` library to connect to a Postgres database and runs a query to fetch the current time from the database using `SELECT NOW()`. Upon receiving the data, it renders the index view with the fetched time, sending it to the client along with a title.

If an error occurs during the database query, the code catches the error, logs it, and sends a 500 status response to the client, indicating that there was an issue querying the database.

The page is only rendered after successfully receiving the database response to ensure proper handling of the data.

4. Open the `views/index.pug` file, and update it to display the `timeFromDB` value on the page.

```html
Expand Down

0 comments on commit c237d78

Please sign in to comment.