{"id":136204,"date":"2025-08-22T12:34:47","date_gmt":"2025-08-22T09:34:47","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=136204"},"modified":"2025-08-22T12:34:49","modified_gmt":"2025-08-22T09:34:49","slug":"how-to-create-database-seed-scripts-in-node-js","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html","title":{"rendered":"How to Create Database Seed Scripts in Node.js"},"content":{"rendered":"<p>Database seeding is a crucial step in application development. It involves populating your database with initial or test data automatically, which helps during development, testing, and demos. For Node.js applications, seed scripts can be built to insert default or complex datasets consistently. Let\u2019s explore how to build database seed scripts for a Node.js application using PostgreSQL.<\/p>\n<h2><a name=\"section-1\"><\/a>1. What is Node.js and Data Seeding in a Node.js Application?<\/h2>\n<p><a href=\"https:\/\/nodejs.org\/\" target=\"_blank\" rel=\"noopener\">Node.js<\/a> is an open-source, cross-platform JavaScript runtime environment built on Chrome&#8217;s <a href=\"https:\/\/v8.dev\/\" target=\"_blank\" rel=\"noopener\">V8 JavaScript engine<\/a>. It enables developers to run JavaScript code outside the browser, making it a popular choice for backend development, APIs, and microservices. Node.js uses an event-driven, non-blocking I\/O model, which makes it highly efficient and suitable for building scalable network applications.<\/p>\n<p>In backend systems, data seeding refers to pre-populating a database with initial data. This is typically achieved by writing scripts in Node.js that insert default or sample records into the database. Data seeding is especially valuable for:<\/p>\n<ul>\n<li>Setting up <a href=\"https:\/\/en.wikipedia.org\/wiki\/Test_environment\" target=\"_blank\" rel=\"noopener\">test environments<\/a> with predictable datasets<\/li>\n<li>Providing default configurations for new installations<\/li>\n<li>Enabling rapid prototyping during early stages of development<\/li>\n<li>Creating demo versions of applications with realistic data<\/li>\n<\/ul>\n<p>Data seeding in Node.js applications ensures that developers, testers, and CI\/CD pipelines start with a consistent dataset every time, reducing environment-specific bugs and easing onboarding for new team members.<\/p>\n<h3>1.1 Setting up Node.js<\/h3>\n<p>To set up Node.js on Windows, download the installer from <a href=\"https:\/\/nodejs.org\/en\/download\/\" target=\"_blank\" rel=\"noopener\">here<\/a>. Run the installer, which includes the NPM package manager, and follow the setup wizard. After installation, you can verify Node.js and npm by running:<\/p>\n<pre class=\"brush:bash; wrap-lines:false;\">node -v\nnpm -v\n<\/pre>\n<p><figure id=\"attachment_136209\" aria-describedby=\"caption-attachment-136209\" style=\"width: 480px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2025\/08\/node-npm-installation-img1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-136209\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2025\/08\/node-npm-installation-img1.jpg\" alt=\"Fig. 1: Verifying node and npm installation\" width=\"480\" height=\"91\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2025\/08\/node-npm-installation-img1.jpg 480w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2025\/08\/node-npm-installation-img1-300x57.jpg 300w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><figcaption id=\"caption-attachment-136209\" class=\"wp-caption-text\">Fig. 1: Verifying node and npm installation<\/figcaption><\/figure><\/p>\n<h2><a name=\"section-2\"><\/a>2. Setting Up PostgreSQL<\/h2>\n<p><a href=\"https:\/\/www.postgresql.org\/\" target=\"_blank\" rel=\"noopener\">PostgreSQL<\/a> is a powerful, open-source relational database system. To set it up locally:<\/p>\n<ul>\n<li>Download and install PostgreSQL from the <a href=\"https:\/\/www.postgresql.org\/download\/\" target=\"_blank\" rel=\"noopener\">official site<\/a>.<\/li>\n<li>Create a new database and user for your Node.js application using <code>psql<\/code> or a GUI tool like pgAdmin.<\/li>\n<li>Install the <code>pg<\/code> npm package in your Node.js project to connect to PostgreSQL.<\/li>\n<\/ul>\n<h3>2.1 Installing PostgreSQL Client for Node.js<\/h3>\n<pre class=\"brush:bash; wrap-lines:false;\">npm install pg\n<\/pre>\n<h2><a name=\"section-3\"><\/a>3. Code Example<\/h2>\n<p>Here, we will set up the project, write scripts to insert sample data into the <code>users<\/code> and <code>orders<\/code> tables, and demonstrate how to manage environment-specific seeding.<\/p>\n<h3>3.1 Setup<\/h3>\n<p>Before seeding data, set up a Node.js project:<\/p>\n<pre class=\"brush:bash; wrap-lines:false;\">mkdir pg-seed-example\ncd pg-seed-example\nnpm init -y\nnpm install pg\n<\/pre>\n<h3>3.2 Seed Script<\/h3>\n<p>This script demonstrates how to create a PostgreSQL database, define schemas, and insert sample data using Node.js:<\/p>\n<pre class=\"brush:js; wrap-lines:false;\">\nconst { Pool } = require('pg');\n\n\/\/ PostgreSQL connection pool\nconst pool = new Pool({\n  user: 'your_db_user',\n  host: 'localhost',\n  database: 'your_db_name',\n  password: 'your_db_password',\n  port: 5432,\n});\n\n\/\/ Create tables if not exist\nasync function createSchema() {\n  await pool.query(`\n    CREATE TABLE IF NOT EXISTS users (\n      id VARCHAR(50) PRIMARY KEY,\n      name VARCHAR(100),\n      email VARCHAR(100) UNIQUE,\n      street VARCHAR(200),\n      city VARCHAR(100),\n      zip VARCHAR(20)\n    );\n  `);\n\n  await pool.query(`\n    CREATE TABLE IF NOT EXISTS products (\n      id VARCHAR(50) PRIMARY KEY,\n      name VARCHAR(100),\n      price NUMERIC(10,2)\n    );\n  `);\n\n  await pool.query(`\n    CREATE TABLE IF NOT EXISTS orders (\n      id VARCHAR(50) PRIMARY KEY,\n      user_id VARCHAR(50) REFERENCES users(id)\n    );\n  `);\n\n  await pool.query(`\n    CREATE TABLE IF NOT EXISTS order_items (\n      order_id VARCHAR(50) REFERENCES orders(id),\n      product_id VARCHAR(50) REFERENCES products(id),\n      quantity INT,\n      PRIMARY KEY (order_id, product_id)\n    );\n  `);\n\n  console.log('Database schema created or verified.');\n}\n\n\/\/ Seed user data\nasync function seedUsers() {\n  const users = [\n    { id: 'user1', name: 'Alice', email: 'alice@example.com', street: '123 Elm St', city: 'Metropolis', zip: '12345' },\n    { id: 'user2', name: 'Bob', email: 'bob@example.com', street: '456 Oak St', city: 'Gotham', zip: '67890' },\n  ];\n\n  for (const user of users) {\n    await pool.query(\n      `INSERT INTO users(id, name, email, street, city, zip) VALUES($1,$2,$3,$4,$5,$6) ON CONFLICT (id) DO NOTHING`,\n      [user.id, user.name, user.email, user.street, user.city, user.zip]\n    );\n    console.log(\\`Seeded user: \\${user.name}\\`);\n  }\n}\n\n\/\/ Seed product data\nasync function seedProducts() {\n  const products = [\n    { id: 'prod1', name: 'Laptop', price: 1200 },\n    { id: 'prod2', name: 'Mouse', price: 20 },\n    { id: 'prod3', name: 'Keyboard', price: 50 },\n  ];\n\n  for (const product of products) {\n    await pool.query(\n      `INSERT INTO products(id, name, price) VALUES($1,$2,$3) ON CONFLICT (id) DO NOTHING`,\n      [product.id, product.name, product.price]\n    );\n    console.log(\\`Seeded product: \\${product.name}\\`);\n  }\n}\n\n\/\/ Seed order data\nasync function seedOrders() {\n  const orders = [\n    { id: 'order1', userId: 'user1' },\n    { id: 'order2', userId: 'user1' },\n    { id: 'order3', userId: 'user2' },\n  ];\n\n  for (const order of orders) {\n    await pool.query(\n      `INSERT INTO orders(id, user_id) VALUES($1,$2) ON CONFLICT (id) DO NOTHING`,\n      [order.id, order.userId]\n    );\n    console.log(\\`Seeded order: \\${order.id} for user \\${order.userId}\\`);\n  }\n}\n\n\/\/ Seed order items (many-to-many relationship)\nasync function seedOrderItems() {\n  const orderItems = [\n    { orderId: 'order1', productId: 'prod1', quantity: 1 },\n    { orderId: 'order1', productId: 'prod2', quantity: 2 },\n    { orderId: 'order2', productId: 'prod2', quantity: 1 },\n    { orderId: 'order3', productId: 'prod3', quantity: 1 },\n  ];\n\n  for (const item of orderItems) {\n    await pool.query(\n      `INSERT INTO order_items(order_id, product_id, quantity) VALUES($1,$2,$3) ON CONFLICT (order_id, product_id) DO NOTHING`,\n      [item.orderId, item.productId, item.quantity]\n    );\n    console.log(\\`Seeded order item: order \\${item.orderId} -&gt; product \\${item.productId}\\`);\n  }\n}\n\n\/\/ Main seeding function\nasync function seed() {\n  if (process.env.NODE_ENV === 'development') {\n    console.log('Running development seed...');\n    await createSchema();\n    await seedUsers();\n    await seedProducts();\n    await seedOrders();\n    await seedOrderItems();\n  } else {\n    console.log('No seeding performed for environment:', process.env.NODE_ENV);\n  }\n  await pool.end();\n}\n\nseed()\n  .then(() =&gt; {\n    console.log('Seeding complete.');\n    process.exit(0);\n  })\n  .catch((error) =&gt; {\n    console.error('Seeding failed:', error);\n    process.exit(1);\n  });\n<\/pre>\n<h4>3.2.1 Code Explanation<\/h4>\n<p>This Node.js script connects to a PostgreSQL database using the <code>pg<\/code> module, creates required tables if they do not exist, and inserts sample data for development environments. The <code>createSchema<\/code> function defines tables for <code>users<\/code>, <code>products<\/code>, <code>orders<\/code>, and <code>order_items<\/code> using <code>CREATE TABLE IF NOT EXISTS<\/code>, ensuring proper primary and foreign key relationships to maintain data integrity, including a many-to-many link between orders and products. Separate seeding functions (<code>seedUsers<\/code>, <code>seedProducts<\/code>, <code>seedOrders<\/code>, <code>seedOrderItems<\/code>) insert predefined data using parameterized <code>INSERT<\/code> queries with <code>ON CONFLICT<\/code> clauses to avoid duplicate entries. The <code>seed<\/code> function orchestrates schema creation and data insertion, executing only when <code>NODE_ENV<\/code> is set to &#8220;development&#8221;, and finally closes the database connection pool, logging success or failure messages for tracking purposes.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3>3.3 package.json Scripts<\/h3>\n<p>Add a script to <code>package.json<\/code> for running seeds:<\/p>\n<pre class=\"brush:js; wrap-lines:false;\">{\n  \"name\": \"pg-seed-example\",\n  \"version\": \"1.0.0\",\n  \"main\": \"seed.js\",\n  \"scripts\": {\n    \"seed:dev\": \"NODE_ENV=development node seed.js\"\n  },\n  \"dependencies\": {\n    \"pg\": \"^8.0.0\"\n  }\n}\n<\/pre>\n<h4>3.3.1 Code Explanation<\/h4>\n<p>This <code>package.json<\/code> file defines a Node.js project named &#8220;pg-seed-example&#8221; with version 1.0.0 and a main entry point of <code>seed.js<\/code>. It includes a <code>scripts<\/code> section with a custom script <code>seed:dev<\/code> that sets the environment variable <code>NODE_ENV<\/code> to &#8220;development&#8221; and runs the seed script. The <code>dependencies<\/code> section lists <code>pg<\/code> version 8.0.0 as the required package to enable PostgreSQL database connectivity from Node.js.<\/p>\n<h3>3.4 Running the Seed Script<\/h3>\n<p>Execute the seed script in development mode:<\/p>\n<pre class=\"brush:bash; wrap-lines:false;\">npm run seed:dev\n<\/pre>\n<p>This command sets the environment to <code>development<\/code> and triggers the <code>seed.js<\/code> script, ensuring that seeding only happens in the intended environment.<\/p>\n<h3>3.5 Output<\/h3>\n<p>Upon successful execution, the console will show:<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">\nRunning development seed...\nDatabase schema created or verified.\nSeeded user: Alice\nSeeded user: Bob\nSeeded product: Laptop\nSeeded product: Mouse\nSeeded product: Keyboard\nSeeded order: order1 for user user1\nSeeded order: order2 for user user1\nSeeded order: order3 for user user2\nSeeded order item: order order1 -&gt; product prod1\nSeeded order item: order order1 -&gt; product prod2\nSeeded order item: order order2 -&gt; product prod2\nSeeded order item: order order3 -&gt; product prod3\nSeeding complete.\n<\/pre>\n<p>This output shows that the script inserted users, products, orders, and the many-to-many relationships between orders and products without errors, confirming that the database seeding was successful and complete.<\/p>\n<h2><a name=\"section-4\"><\/a>4. Unit Testing the Seed Script<\/h2>\n<p>Unit testing the seed script helps validate logic without interacting with a real database. By mocking database queries, we can simulate PostgreSQL responses and verify that the seed functions are executing correctly.<\/p>\n<h3>4.1 Benefits of Unit Testing Seed Scripts<\/h3>\n<ul>\n<li>Prevent Data Corruption: Avoids modifying real or production databases during test runs.<\/li>\n<li>Verify Logic: Ensures seed functions insert the expected data and maintain correct relationships.<\/li>\n<li>Fast Feedback: Tests run quickly as they do not require a live database connection.<\/li>\n<\/ul>\n<h3>4.2 Example Unit Test using Jest<\/h3>\n<pre class=\"brush:js; wrap-lines:false;\">\n\/\/ seed.test.js\nconst { seedUsers } = require('.\/seed'); \/\/ import function to test\nconst { Pool } = require('pg');\n\n\/\/ Mock the pg module\njest.mock('pg', () =&gt; {\n  const mPool = { query: jest.fn(), end: jest.fn() };\n  return { Pool: jest.fn(() =&gt; mPool) };\n});\n\ndescribe('Seed Script Tests', () =&gt; {\n  let pool;\n\n  beforeAll(() =&gt; {\n    pool = new Pool();\n  });\n\n  test('should insert users correctly', async () =&gt; {\n    pool.query.mockResolvedValueOnce({}); \/\/ mock query result\n    await seedUsers();\n    expect(pool.query).toHaveBeenCalled();\n    expect(pool.query).toHaveBeenCalledWith(\n      expect.stringContaining('INSERT INTO users'),\n      expect.any(Array)\n    );\n  });\n});\n<\/pre>\n<p>This Jest-based test suite mocks the <code>pg<\/code> module so that no real database connection is made. It intercepts calls to <code>pool.query<\/code> and verifies that the correct SQL statement (an <code>INSERT INTO<\/code> command) is executed with the expected parameters. This ensures the seed function logic is correct, prevents accidental data modification, and provides fast, isolated feedback during development.<\/p>\n<h2><a name=\"section-5\"><\/a>5. Documenting Seeding Practices<\/h2>\n<p>Maintain clear documentation to facilitate onboarding, collaboration, and consistency:<\/p>\n<ul>\n<li>Purpose and Scope: Explain why seeding is needed and which tables are seeded.<\/li>\n<li>Seed Data Structure: Describe data models, relationships, and default values.<\/li>\n<li>How to Run Seeds: Include commands, environment variables, and expected output.<\/li>\n<li>Environment Considerations: Specify which environments support seeding.<\/li>\n<li>Updating Seed Data: Outline procedures for modifying seed data over time.<\/li>\n<li>Dependencies and Tools: List required Node.js packages like <code>pg<\/code>.<\/li>\n<li>Known Issues and Limitations: Note any constraints such as performance considerations.<\/li>\n<\/ul>\n<h2><a name=\"section-6\"><\/a>6. Conclusion<\/h2>\n<p>Database seeding is a vital practice in Node.js application development that ensures your PostgreSQL database is consistently populated with necessary initial or test data. Automating this process with seed scripts enables rapid setup of development and test environments, reliable demos, and reduced environment-specific bugs. By integrating seeding into your workflow, writing unit tests, and documenting your practices, your team can maintain stable, predictable, and maintainable application data efficiently.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Database seeding is a crucial step in application development. It involves populating your database with initial or test data automatically, which helps during development, testing, and demos. For Node.js applications, seed scripts can be built to insert default or complex datasets consistently. Let\u2019s explore how to build database seed scripts for a Node.js application using &hellip;<\/p>\n","protected":false},"author":26931,"featured_media":80864,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2096],"tags":[1387,2065],"class_list":["post-136204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js","tag-firebase","tag-nodejs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Create Database Seed Scripts in Node.js - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"How to build database seed scripts for your node application: Learn how to build database seed scripts for Node.js app.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Database Seed Scripts in Node.js - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"How to build database seed scripts for your node application: Learn how to build database seed scripts for Node.js app.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-22T09:34:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-22T09:34:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/08\/nodejs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin Batra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin Batra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html\"},\"author\":{\"name\":\"Yatin Batra\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\"},\"headline\":\"How to Create Database Seed Scripts in Node.js\",\"datePublished\":\"2025-08-22T09:34:47+00:00\",\"dateModified\":\"2025-08-22T09:34:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html\"},\"wordCount\":933,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/nodejs-logo.jpg\",\"keywords\":[\"Firebase\",\"nodejs\"],\"articleSection\":[\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html\",\"name\":\"How to Create Database Seed Scripts in Node.js - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/nodejs-logo.jpg\",\"datePublished\":\"2025-08-22T09:34:47+00:00\",\"dateModified\":\"2025-08-22T09:34:49+00:00\",\"description\":\"How to build database seed scripts for your node application: Learn how to build database seed scripts for Node.js app.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/nodejs-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/nodejs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-create-database-seed-scripts-in-node-js.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Node.js\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\\\/node-js\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Create Database Seed Scripts in Node.js\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\",\"name\":\"Yatin Batra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"caption\":\"Yatin Batra\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\\\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/yatin-batra\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create Database Seed Scripts in Node.js - Java Code Geeks","description":"How to build database seed scripts for your node application: Learn how to build database seed scripts for Node.js app.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html","og_locale":"en_US","og_type":"article","og_title":"How to Create Database Seed Scripts in Node.js - Java Code Geeks","og_description":"How to build database seed scripts for your node application: Learn how to build database seed scripts for Node.js app.","og_url":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2025-08-22T09:34:47+00:00","article_modified_time":"2025-08-22T09:34:49+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/08\/nodejs-logo.jpg","type":"image\/jpeg"}],"author":"Yatin Batra","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin Batra","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html"},"author":{"name":"Yatin Batra","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d"},"headline":"How to Create Database Seed Scripts in Node.js","datePublished":"2025-08-22T09:34:47+00:00","dateModified":"2025-08-22T09:34:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html"},"wordCount":933,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/08\/nodejs-logo.jpg","keywords":["Firebase","nodejs"],"articleSection":["Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html","url":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html","name":"How to Create Database Seed Scripts in Node.js - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/08\/nodejs-logo.jpg","datePublished":"2025-08-22T09:34:47+00:00","dateModified":"2025-08-22T09:34:49+00:00","description":"How to build database seed scripts for your node application: Learn how to build database seed scripts for Node.js app.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/08\/nodejs-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/08\/nodejs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/how-to-create-database-seed-scripts-in-node-js.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"Node.js","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript\/node-js"},{"@type":"ListItem","position":5,"name":"How to Create Database Seed Scripts in Node.js"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d","name":"Yatin Batra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","caption":"Yatin Batra"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/yatin-batra"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/136204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/26931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=136204"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/136204\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/80864"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=136204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=136204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=136204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}