I am attempting to establish a connection to a Postgres database using typescript. For the ORM, I have opted for sequelize-typescript
. The issue lies in the fact that the script seems to hang at await sequelize.sync();
. Below is the content of the sequelize.ts
file:
import {Sequelize} from 'sequelize-typescript';
import { config } from './config/config';
const c = config.dev;
// Initialize a new Sequelize instance!
export const sequelize = new Sequelize({
"username": c.username,
"password": c.password,
"database": c.database,
"host": c.host,
dialect: 'postgres',
storage: ':memory:',
});
Moreover, here is the model class file named Product.ts
:
import {Table, Column, Model, HasMany, PrimaryKey, CreatedAt, UpdatedAt, ForeignKey} from 'sequelize-typescript';
@Table
export class Product extends Model<Product> {
@Column
public brand: string;
@Column
public price: number;
@Column
public description!: string;
@Column
public imgUrl!: string;
@Column
public cateogry: string;
}
Furthermore, let's delve into the contents of the server.ts
, where I make use of sequelize:
(async () => {
await sequelize.addModels(V0MODELS);
//The issue arises at this point
await sequelize.sync();
const app = express();
const port = 8100; // default port to listen
app.use(bodyParser.json());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://localhost:8100");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
});
app.use('/api/v0/', IndexRouter);
// Root URI call
app.get( "/", async ( req, res ) => {
res.send( "/api/v0/" );
} );
// Start the Server
app.listen( port, () => {
console.log( `server running http://localhost:${ port }` );
console.log( `press CTRL+C to stop server, please :)` );
} );
})();
Finally, provided below is the content within the package.json
file:
{
"name": "bagsshoes-server",
"version": "1.0.0",
"description": "",
"main": "src/server.js",
"scripts": {
…
},
"keywords": [],
"author": "Fahima Mokhtari",
"license": "ISC",
"dependencies": {
…
},
"devDependencies": {
…
}
}
Despite my attempts with try
and catch
, no errors were displayed, leaving me even more perplexed.
Any form of assistance would be immensely appreciated!
PS:
For context, I am working on Windows with Node version V14.7.0