Node v14, server backend needs Observable and connection to PostgreSql.
- To create Observable,
import { Observable } from 'rxjs';
is needed. - Must add
"type": "module"
into pakage.json elseWarning: To load an ES module, set "type": "module" in the package.json
- But it makes
require
not working for Postgre connection.
index.js
import { Observable } from 'rxjs';
const observable = new Observable(
subscriber =>
{
...
});
observable.subscribe({...});
console.log('just after subscribe');
To connect to PostgreSql,
const pgp = require('pg-promise')();
const db = pgp({...});
Now getting ReferenceError: require is not defined
.
How can I have both?
import * as pgPromise from 'pg-promise'; const pgp = pgPromise({});
got TypeError: pgPromise is not a function pgp version 10.11.0 – Hyperopianpm install typescript -g
,npm install
, went to typescript folder bycd node_modules\typescript
, rantsc
got a help screen. So I didtsc --init
,tsc --build tsconfig.json
. F5, same pgPromise is not a function. Any other steps missing? – Hyperopia