JavaScript how to specify ormconfig.ts for typeorm?

I have created a sample typeorm project using the typeorm cli which has ormconfig.json by default:

{
   "type": "postgres",
   "host": "localhost",
   "port": 5432,
   "username": "postgres",
   "password": "postgres",
   "database": "test",
   "synchronize": false,
   "entities": [
      "src/entity/**/*.ts"
   ],
   "migrations": [
      "database/migrations/**/*.ts"
   ],
   "subscribers": [
      "src/subscriber/**/*.ts"
   ],
   "cli": {
      "entitiesDir": "src/entity",
      "migrationsDir": "database/migrations",
      "subscribersDir": "src/subscriber"
   }
}

this is the directory structure:

-database
  -migrations
-src
  -entity
-ormconfig.json

This creates the migrations in the database/migrations folder properly as well as executes the migrations from it.

I replaced ormconfig.json with the following ormconfig.ts :

export default {
    type: 'postgres',
    host: 'localhost',
    port: 5432,
    username: 'postgres',
    password: 'postgres',
    database: 'test',
    synchronize: false,
    "entities": [
        "src/entity/**/*.ts"
    ],
    "migrations": [
         "database/migrations/**/*.ts"
    ],
    "subscribers": [
        "src/subscriber/**/*.ts"
    ],
    "cli": {
        "entitiesDir": "src/entity",
        "migrationsDir": "database/migrations",
        "subscribersDir": "src/subscriber"
    }
};

this however creates migrations in the root directory instead of inside database/migrations.

Can anyone help me in figuring out whats missing here and how i can use ormconfig.ts to generate migrations inside the intended directory?

Thanks!

Answer:1

At the time of writing, TypeORM only look for ormconfig.json and ignores ormconfig.ts. There is work in progress to support it though.

Beside having ormconfig.json you need these commands in your package.json.

"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm",
"migration:generate": "npm run typeorm -- migration:generate --config src/config/ormconfig.json --connection  --name ",
"migration:run": "npm run typeorm -- migration:run"
Answer:2

Hey i up this conversation since i can propose you a solution.

You can put the following line in your package.json file:

"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config server/environments/database.ts",

And your ts config must export directly the config by doing that:

export = { /* your config */ };

As you can see, you can also specify the path of your config. No need for your config to be at the root level of your project.

Hope that will help you

Answer:3

I am using html2canvas.js to create a <canvas> image from a div on a page. What I'd like to do is send the rendered base64 image to a cfc via ajax so I can actually save the image to a folder on ...

I am using html2canvas.js to create a <canvas> image from a div on a page. What I'd like to do is send the rendered base64 image to a cfc via ajax so I can actually save the image to a folder on ...

  1. send base64 image to server
  2. send base64 image to web api c#
  3. send base64 image in email
  4. send base64 image to server python
  5. send base64 image postman
  6. send base64 image to server c#
  7. send base64 image in email java
  8. send base64 image to server angular 4
  9. send base64 image in json
  10. send base64 image in url
  11. send base64 image to server php
  12. send base64 image to server android
  13. send base64 image to server nodejs
  14. send base64 image to web api
  15. send base64 image in email c#
  16. send base64 image to server javascript
  17. send base64 image to server android volley
  18. send base64 image in email php
  19. send base64 image ajax
  20. send base64 image nodejs

I have the following setup where a custom checkmark is added to style the radio buttons. but it also adds that checkmark to the text type inputs. var changed =function(){ Array.from(...

I have the following setup where a custom checkmark is added to style the radio buttons. but it also adds that checkmark to the text type inputs. var changed =function(){ Array.from(...

I need to take some non-trivial javascript and ensure that all code paths have code that is valid. For example: var num = 1; if (num == 2) { badFunctionName(); } and I need to do this from C#. ...

I need to take some non-trivial javascript and ensure that all code paths have code that is valid. For example: var num = 1; if (num == 2) { badFunctionName(); } and I need to do this from C#. ...

  1. verify javascript code online
  2. verify javascript code
  3. check javascript code
  4. check javascript code online
  5. check javascript code for browser compatibility
  6. check javascript code for errors
  7. check javascript code for errors online
  8. check javascript code syntax
  9. check javascript code quality
  10. check javascript code style
  11. verification code javascript
  12. javascript check code syntax online
  13. javascript check code execution time
  14. javascript check code coverage
  15. age verification javascript code
  16. email verification javascript code

Suppose you have an array that is modified by one asynchronous process and then you have another asynchronous process that reads from the same array. Modifications and reads are done synchronously. ...

Suppose you have an array that is modified by one asynchronous process and then you have another asynchronous process that reads from the same array. Modifications and reads are done synchronously. ...