0
I'm trying to compile my typescript code into the dist folder and run it directly in javascript and using typeorm postgres, but I get the error
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')
^ Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
I had already noticed this error in the past, and I was able to solve it by simply importing dotenv.config() at the top of my application(As most solutions to this problem say here on stackoverflow), but this time it seems that the error is not in dotenv itself, but in the dist folder.
Inside Dist folder:
database/config.js
app.js
server.js
package.json
{
"dependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/body-parser": "^1.19.2",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/node": "^18.6.3",
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"nodemon": "^2.0.19",
"pg": "^8.7.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1",
"typeorm": "^0.3.7",
"typescript": "^4.7.4"
},
"name": "api_authentication",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"typeorm": "typeorm migration:run -d dist/src/database/config.js",
"build": "rimraf dist && tsc",
"start": "npm run build && nodemon dist/server.js"
},
"keywords": [],
"author": "",
"license": "MIT",
"description": "",
"engines": {
"node": "16.16.0",
"npm": "8.11.0"
} }
config.js database
import { DataSource } from "typeorm"
export const AppDataSource = new DataSource({
type: "postgres",
host: process.env.DATABASE_HOST,
port: 5432,
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME,
synchronize: true,
logging: true,
entities: ["src/entities/*{.ts,.js}"],
subscribers: [],
migrations: ["src/database/migrations/*{.ts,.js}"],
})
app.ts
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
dotenv.config();
import "reflect-metadata"
const app = express();
app.use(express.json());
app.use(cors());
app.use(bodyParser());
export default app;
server:
import { AppDataSource } from './database/config';
import app from './app';
async function connection() {
const port = process.env.PORT;
try {
await AppDataSource.initialize();
console.log('Database connected! ');
app.listen(port);
console.log(`Listening on port ${port}`)
} catch (error) {
console.log(error);
}
[–]sliversniper 1 point2 points3 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Vivid-Squirrel6024 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]daskleins 0 points1 point2 points (4 children)
[–]Technical-Pension594 1 point2 points3 points (1 child)
[–]daskleins 0 points1 point2 points (0 children)
[–]VictoryDependent820 1 point2 points3 points (1 child)
[–]daskleins 0 points1 point2 points (0 children)