Node v14, server backend needs Observable and connection to PostgreSql.
import { Observable } from 'rxjs';
is needed."type": "module"
into pakage.json else Warning: To load an ES module, set "type": "module" in the package.json
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?
After much research and try, come back to the same spot, simply replace require
with import
. As an example of above,
Original:
const pgp = require('pg-promise')();
const db = pgp({...});
New:
import pgPromise from 'pg-promise';
const pgp = pgPromise({...});
const db = pgp({...});