I have two set of commands that I want to run sequentially first is the database seed and the second is the actual server start but for some reason nodejs doesnot run the second command let me show you the script
package.json
"scripts": {
"start": "ts-node src/seeder/seedCompanies && ts-node-dev --respawn src/index.ts"
}
the first command is the seed the code for that is
seedCompanies.ts
import { Company } from "../entity/Company";
import { Product } from "../entity/Product";
import { ProductColor } from "../entity/ProductColor";
import { ProductSize } from "../entity/ProductSize";
import { createConnection } from "typeorm";
import bcrypt from "bcryptjs";
createConnection().then((connection): Promise<void> => {
for (let i = 0; i <= 1; i++) {
let company = new Company();
company.name = `Company ${Math.random().toString(36).substring(4)}`,
company.email = `email${Math.random().toString(36).substring(4)}@gmail.com`,
company.address = "Demo Address",
company.password = bcrypt.hashSync('123', 10),
company.website = "website.com"
connection.manager
.save(company)
.then(company => {
for (let j = 0; j < 10; j++) {
let product = new Product();
//randon name for product as seeder will run on every server start
product.name = `Product ${Math.random().toString(36).substring(5)}`;
product.description = "Seed product";
product.image = "https://picsum.photos/200/300";
product.company = <any>company.id;
connection.manager
.save(product).then(product => {
let productColor = new ProductColor();
productColor.color = "#000";
productColor.product = <any>product.id
connection.manager
.save(productColor)
let productSize = new ProductSize();
productSize.size = "XL";
productSize.product = <any>product.id
connection.manager
.save(productSize)
})
}
});
}
return <any>null;
})
now the seeding works great I can see the data added but the problem is nodejs is stuck at the end of this script doesnot show any error
query: SELECT `ProductSize`.`id` AS `ProductSize_id`, `ProductSize`.`size` AS `ProductSize_size` FROM `product_size` `ProductSize` WHERE `ProductSize`.`id` = ? -- PARAMETERS: [60]
query: COMMIT
query: COMMIT
query: COMMIT
these are the last lines in the terminal i tried using
process.exit(1)
but that closes the server how can i move to the next thread/command in package.json?