I have cloned the following repo from github:
https://github.com/FACed-Off/learn-node-postgres
and am current working on the following commit hash in the master branch:
3785d42e8e8a954a363ee108d5263bb51780a0ea
However I am unable to progress at the point where I run the server, as the init.sql
file does not seem to be recognised. VScode claims there is a syntax error despite the code being correct, however upon running this code on another machine, the expected output occurs which is:
"...a big object logged in your terminal. This is the entire result of our database query. The bit we're actually interested in is the "rows" property. This is an array of each row in the table we're selecting from. Each row is represented as an object, with a key/value entry for each column."
The output I get on this current machine upon running npm run dev
is the "hello world" text at the localhost:3000 endpoint, however I do not get any sort of output from the code in the home function for the db.query method:
db.query("SELECT * FROM users").then((result) => {
console.log(result);
});
I have verified that postgres is installed by running which psql
, to which I get the output /usr/local/bin/psql
I have verified that the local database is setup by running
pgcli
\connect learn_node_postgres
SELECT * FROM users
and receiving the expected output of a table representing all the entries in the users table in the terminal
I have verified that the required npm modules of dotenv
and pg
have been installed by checking the dev dependencies and seeing
"dependencies": {
"dotenv": "^8.2.0",
"nodemon": "^2.0.2",
"pg": "^7.18.2"
},