1

I'm kind of new with Typescript and 100% new with Sequelize. I have done only changes related to the postgres config in the .config/config file only to add the dev db config as shown below:

export const config = {
  "dev": {
    "username": "postgres",
    "password": "postgres",
    "database": "baseDB",
    "host": "localhost",
    "dialect": "postgres"
  },
  ...
}

The db is running un a docker container on my local PC, I have connection to the container and I can navigate the db with DataGrip connected to the container, which means that the DB config is correct.

See my configs:

package.json file

{
  "name": "sample-restapi",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "tsc": "tsc",
    "dev": "ts-node-dev ./src/server.ts",
    "prod": "tsc && node ./www/server.js",
    "clean": "rimraf www/ || true",
    "build": "npm run clean && tsc && cp -rf src/config www/config && cp .npmrc www/.npmrc && cp package.json www/package.json && cd www && zip -r Archive.zip . && cd ..",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "Name here",
  "license": "",
  "dependencies": {
    "@types/bcrypt": "^3.0.0",
    "@types/jsonwebtoken": "^8.3.2",
    "aws-sdk": "^2.492.0",
    "bcrypt": "^5.0.0",
    "body-parser": "^1.19.0",
    "email-validator": "^2.0.4",
    "express": "^4.17.1",
    "jsonwebtoken": "^8.5.1",
    "pg": "^7.11.0",
    "pg-hstore": "^2.3.4",
    "reflect-metadata": "^0.1.13",
    "sequelize": "^5.10.0",
    "sequelize-typescript": "^0.6.11"
  },
  "devDependencies": {
    "@types/bluebird": "^3.5.33",
    "@types/express": "^4.17.9",
    "@types/node": "^11.15.42",
    "@types/sequelize": "^4.28.9",
    "@types/validator": "^10.11.3",
    "chai": "^4.2.0",
    "chai-http": "^4.3.0",
    "mocha": "^6.2.3",
    "rimraf": "^3.0.2",
    "ts-node-dev": "^1.1.1",
    "tslint": "^5.20.1",
    "typescript": "^3.9.7"
  }
}

Config file

export const config = {
  "dev": {
    "username": "postgres",
    "password": "postgres",
    "database": "baseDB",
    "host": "localhost",
    "dialect": "postgres",
    "aws_region": "us-east-2",
    "aws_profile": "default",
    "aws_media_bucket": "udagram-ruttner-dev"
  },
  "jwt": {
    "secret": " "
  },
  "prod": {
    "username": "",
    "password": "",
    "database": "udagram_prod",
    "host": "",
    "dialect": "postgres"
  }
}

Sequelize config

import {Sequelize} from 'sequelize-typescript';
import { config } from './config/config';


const c = config.dev;

// Instantiate new Sequelize instance!
export const sequelize = new Sequelize({
  "username": c.username,
  "password": c.password,
  "database": c.database,
  "host":     c.host,

  dialect: 'postgres',
  storage: ':memory:',
});

server.ts

import express from 'express';
import { sequelize } from './sequelize';

import { IndexRouter } from './controllers/v0/index.router';

import bodyParser from 'body-parser';

import { V0MODELS } from './controllers/v0/model.index';

(async () => {
 
  await sequelize.addModels(V0MODELS);
  
 /*THE APPLICATION STOP IN THIS LINE*/
  await sequelize.sync();
  /*NOTHING BELOW IS EXECUTED AND NO ERROR LOGGED EVEN ADDING A TRY CATCH 
    THERE ARE NO ERRORS*/

  const app = express();
  const port = process.env.PORT || 8080; // default port to listen
  
  app.use(bodyParser.json());
  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` );
  } );
})();

V0MODELS definition

import { FeedItem } from './feed/models/FeedItem';
import { User } from './users/models/User';

export const V0MODELS = [ FeedItem, User ];

Every time I tried to run npm run dev I have no errors, no nothing, the application just stop after this line and nothing else is executed

await sequelize.sync();
I'm using node version: v16.14.0, npm version: 8.3.1

What am I doing wrong? Note: you can assume that npm i is the first thing that I have ran.

Console output:

PS path\simple-restapi> npm run dev

> [email protected] dev
> ts-node-dev ./src/server.ts

[INFO] 12:56:52 ts-node-dev ver. 1.1.1 (using ts-node ver. 9.1.1, typescript ver. 3.9.7)
sequelize config:  {
  dialect: 'postgres',
  dialectModule: null,
  dialectModulePath: null,
  host: 'localhost',
  protocol: 'tcp',
  define: { timestamps: false, freezeTableName: true },
  query: {},
  sync: {},
  timezone: '+00:00',
  clientMinMessages: 'warning',
  standardConformingStrings: true,
  logging: [Function: log],
  omitNull: false,
  native: false,
  replication: false,
  ssl: undefined,
  pool: {},
  quoteIdentifiers: true,
  hooks: {},
  retry: { max: 5, match: [ 'SQLITE_BUSY: database is locked' ] },
  transactionType: 'DEFERRED',
  isolationLevel: null,
  databaseVersion: 0,
  typeValidation: false,
  benchmark: false,
  minifyAliases: false,
  logQueryParameters: false,
  username: 'postgres',
  password: 'postgres',
  database: 'baseDB',
  storage: ':memory:'
}
sequelize: Attempting to add models to sequelize...
sequelize: Models added to sequelize!!!
sequelize: Attempting to sync...
PS path\simple-restapi> 

Somehow is loading the postgres config but it looks like is pointing to SQLite, how can I avoid this?

0

1 Answer 1

1

from your question here it seems u are on the Udacity ALX-cloud developer program. So the quick solution here is to downgrade your node version to 12.0, this issue is not uncommon. You can use NVM to to install node version 12.0 then u can run your npm run dev command and it should now work as expected. You can use this link to guide u on installing NVM and installing a new version of Node with NVM. Goodluck on your program.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for your answer, and yes I'm in the Udacity program. I will try this later, thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.