npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nseed

v1.0.2

Published

A NodeJS CLI Tool for database seeding with auto-generated data.

Downloads

2

Readme

nSeed


Overview

nSeed is an Open-Source CLI Tool for NodeJS used to generate and seed your database with fake data for testing purposes, powered by @faker-js/faker.

Stop wasting time writing seeders with hard-coded data each time you want to test your new application; just make a template and we'll handle the rest!

Installation

You can install it locally, globally or as a dev dependency with both npm and yarn:

  • local:

    npm install nseed or yarn add nseed

  • dev:

    npm install --save-dev nseed or yarn add nseed --dev

  • global:

    npm install -g nseed or yarn global add nseed

Basic Usage

We want nSeed to be an easy and intuitive tool, so having tons of functionalities was not intended apart from what it promises:

" Giving a connection string, a template and the amount of documents to be created, this tool will generate fake data and seed it into your database. "

The most basic usage is as it follows:

nseed [connection string] --db [database name] --tmpl [path to template] --amount [amount]

If you installed it as a dev dependency you can use it with npx:

npx nseed [connection string] --db [database name] --tmpl [path to template] --amount [amount]

Note

Currently we only support MongoDB databases, but we plan to expand it to other kind of databases such as PostgreSQL, MySQL, CouchDB, Redis, etc.

CLI

| Options | Alias | Description | | -------|-------|-------------| | --db | -d | Flag used to specify the name of the database to be seeded. | | --collection | -c | A string denoting the name of the collection to be generated. | | --tmpl | -t | A Flag to specify the path for the templates to be used. | | --amount | -a | The number of documents to be generated. | | --del | N/A | Indicates that the database must be dropped before seeding. | | --version | -v | Displays the current version. | | --help | -h | Displays help. |

Note

The CLI will ask you for any non-provided required argument.

The path for the template MUST be a relative path. (i.e: ./foo/bar.js)

Example:

nseed mongodb://localhost:27017/ -d Test -c Users -t './template.js' -a 2000 --del

Templates

nSeed templates are js/ts files which exports an unnamed function which returns the template object. The structure of the templates should be as it follows:

module.exports = () => {
	return {
		"foo": "bar1",
		"foo": "bar",
		"foo": ["bar"],
		"foo": {
			"foo": "baz",
			"foo": "baz",
			"foo": "baz"
		}
	}
}

The values on the template can be any kind of valid JSON Data Type; but in order to use autogenerated data with the @faker-js/faker methods you must import and instantiate the Types class as follows:

const { Types } = require('nSeed')
const types = new Types()

module.exports = () => {
	return {
		{
			"firstName": types.faker.name.firstName(),
			"lastName": types.faker.name.lastName(),
			"job": types.faker.name.jobTitle(),
			"address" :{
				"line1": "529 14th St NW",
				"line2": "Apt. 742",
				"state": "Florida",
				"zip": 33054,
			},
			"interests": ["Sports", "Videogames", "Technology"],
			"activeUser": true
		}
	}
}

The Types class has an instance of the @faker-js/faker package and some other utility functions you may find useful. You can use any faker method here so you may want to check their documentation to see what you can do!

Here is a list of all functionalities so far:

  • id( value: string | undefined ): It generates a MongoDB ObjectId, you can give it one as a string on the parameters or it will create one randomly.
  • oneOf( any[] ): Randomly picks one of the values of a given array (the array on the parameters is required).
  • newDate( string | undefined ): It generates a date based on the given date-like string. If no value is passed as parameter it will return the current date.

Example:

const { Types } = require('nSeed')
const types = new Types()

module.exports = () => {
	return {
		status: types.oneOf(['active', 'inactive', 'banned', 'bamboozed']),
		firstName: types.faker.name.firstName(),
		lastName: types.faker.name.lastName(),
		gender: types.faker.name.gender(),
		job: types.faker.name.jobTitle()
	}
}

Note

You must have nSeed installed as a dependency on the project in order to import it into your template.

Configuration

You can configure nSeed with a nseed.config.json file; this gives you the capacity to generate specific configuration per each project you and your team are working on, making it suitable for container environments such as Docker.

All the options available on the CLI can be configured through this file:

{
	"url": "mongodb://<user>:<password>@localgost:27017/",
	"collections": [
		{
			"name": "users",
			"template": "./path/to/template",
			"amount": 70
		},
		{
			"name": "activities",
			"template": "./path/to/template"
		},
		{
			"name": "locations",
			"template": "./path/to/template"
		}
	],
	"amount": 125
}

License

Copyright (c) 2022 Facundo Carbonel / nSeed

This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.