0

I'm very confused. This code works on my collaborator's computer, but not mine. We are running the same Heroku work space. I literally just copied his entire last push.

const express = require("express");
const path = require("path");
var parser = require("body-parser");
// heroku has an environment variable
// that determines port
const PORT = process.env.PORT || 5000;
// pool controls connections to the postgres db
const { Pool } = require("pg");
const { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } = require("constants");
const pool = new Pool({
  connectionString:
    "postgres://{heroku pg database URL}",
  ssl: {
    rejectUnauthorized: false,
  },
});

app = express();

app.get("/", (req, res) => {
    res.status(200);
    res.send('Hello World');
  });

app.listen(PORT, () => {
    console.log(
      "Server running at https://rateyourgames.heroku.com/ using port" + PORT
    );
    console.log(process.DATABASE_URL);
  });

It gives me this error:

C:\Users\matth\Full-Stack-Project\src\test.js:10
const pool = new Pool({
             ^

TypeError: Pool is not a constructor
    at Object.<anonymous> (C:\Users\matth\Full-Stack-Project\src\test.js:10:14)
    at Module._compile (internal/modules/cjs/loader.js:1201:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
    at Module.load (internal/modules/cjs/loader.js:1050:32)
    at Function.Module._load (internal/modules/cjs/loader.js:938:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

Update: I discovered that my version of pg does not match the dependency my pg is version 6.14.5 and the dependency is "^8.3.0" I tried running npm i -g pg@8.3.0, but even though the console says the package updated, it is still saying I have version 6.14.5.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
steve
  • 119
  • 7
  • You've just leaked your database credentials. If those are your real credentials you should invalidate them **_immediately_**. They are forever compromised, and you need to generate new ones. Editing them out of your question is _**not enough**_. – ChrisGPT was on strike Aug 05 '20 at 01:58
  • "I discovered that my version of pg does not match the dependency"—is your `package-lock.json` tracked? Are your `node_modules/` tracked? What command are you running to install dependencies? – ChrisGPT was on strike Aug 05 '20 at 01:59
  • Thanks, I'll change them. Fortunately it's just a school project database that's mostly empty except for a few video games – steve Aug 05 '20 at 02:35
  • I use npm i -g – steve Aug 05 '20 at 02:38

1 Answers1

1

Don't use npm i -g for project dependencies.

-g is the global flag, so dependencies are installed either system-wide or user-wide. For application dependencies you should install dependencies to the node_modules/ folder in the project directory.

To install a new dependency, run something like

npm install pg

This adds pg to your project's dependencies in your package.json. It also updates your package-lock.json. Both of these files should (probably) be committed, and your node_modules/ directory should (probably) be ignored.

If you're not installing a new dependency, but rather just want to install all of a project's dependencies, simply run

npm install
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257