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

create-mvc-structure

v1.0.1

Published

A simple CLI tool to generate a Node.js MVC boilerplate with Express and dotenv configuration

Downloads

3

Readme

Sure! Here’s the updated README.md with instructions on how to install globally first and then how to use npx as an alternative.


Create MVC Structure

create-mvc-structure is a CLI tool that generates a Node.js MVC boilerplate with Express.js and dotenv configuration. It helps you set up the project folder structure, necessary files, and automatically installs dependencies.

Features

  • Generates the complete MVC structure for Node.js projects.
  • Pre-configured with express and dotenv.
  • Includes nodemon for automatic restarts during development.
  • Provides post-installation instructions for easy setup.

Installation and Usage

Option 1: Install Globally

To install the package globally, so that you can use it anytime by its command:

npm install -g create-mvc-structure

Once installed, you can create a new MVC project by running:

create-mvc-structure <project-name>

For example:

create-mvc-structure my-app

This will:

  • Create a new directory called my-app.
  • Set up the MVC folder structure inside the my-app directory.
  • Automatically install necessary dependencies (express, dotenv, and nodemon).

Option 2: Use Without Installation (via npx)

You can also use the package without globally installing it by using npx. This way, you’ll always use the latest version:

npx create-mvc-structure <project-name>

For example:

npx create-mvc-structure my-app

1. Navigate into Your Project Folder

Once the project is created, navigate to your newly created project directory:

cd my-app

2. Start the Application

Option 1: Start the Server with npm start

To manually start the server, run:

npm start

This will start your application using node and will run on the port specified in the .env file (default is PORT=8090).

Option 2: Use nodemon for Auto-Restart

For automatic restarts during development, use nodemon by running:

npm run dev

This command will start your server with nodemon, which will automatically restart it whenever changes are detected.

3. Environment Variables

The generated .env file includes default environment variables:

PORT=8090
DATABASE_URL=mongodb://localhost:27017/myapp

You can modify this file to set your own values for the port and other configuration options.

4. Project Folder Structure

Your generated project will have the following structure:

my-app/
│
├── /controllers       # Controllers for handling business logic
├── /models            # Data models (e.g., schemas)
├── /routes            # Route definitions
├── /public            # Public assets like CSS, images, etc.
│   └── /css           # CSS files
├── /views             # View templates (e.g., EJS, Pug)
├── /config            # Configuration files
├── /middleware        # Custom middleware files
├── .gitignore         # Ignored files for version control
├── .env               # Environment variables
├── index.js           # Main entry point for the application
└── package.json       # Project metadata and dependencies

5. Example Code in index.js

Here’s what the generated index.js file looks like:

require('dotenv').config();
const express = require('express');
const app = express();
const path = require('path');

const PORT = process.env.PORT || 8090;

// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));

// Routes
// Define your routes here
// app.use('/', require('./routes'));

// Start the server
app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

6. Next Steps

Now that your project is set up, you can:

  • Define Routes: Add your application routes inside the routes directory.
  • Implement Controllers: Implement your business logic in the controllers directory.
  • Define Models: Set up your data models in the models directory.
  • Add Views: If using server-side rendering, place your view templates (e.g., EJS or Pug) in the views directory.

License

This project is licensed under the MIT License.


Instructions Summary:

  1. Install Globally:

    • npm install -g create-mvc-structure
    • Use create-mvc-structure <project-name> to create a new project.
  2. Or Use via npx:

    • npx create-mvc-structure <project-name> (no installation required).
  3. Navigate to the Project Folder:

    • cd <project-name>
  4. Start the Project:

    • Manual Start: Run npm start to start the server.
    • Development Mode: Run npm run dev to start with nodemon.
  5. Edit Environment Variables:

    • Customize the .env file to change the default settings.