Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/a-tetarwal/ejs-mongodb

A simple CRUD application using Express, EJS, and MongoDB.
https://github.com/a-tetarwal/ejs-mongodb

backend crud-application crud-operations ejs ejs-templates express mongodb mongoose

Last synced: 2 days ago
JSON representation

A simple CRUD application using Express, EJS, and MongoDB.

Awesome Lists containing this project

README

        

# EJS-MongoDB

A simple CRUD application using Express, EJS, and MongoDB.

## Features

- View a list of users
- Create new users
- Edit existing users
- Delete users

## Prerequisites

- Node.js
- MongoDB

## Getting Started

### Installation

1. Clone the repository:

```bash
git clone https://github.com/yourusername/EJS-MongoDB.git
cd EJS-MongoDB
```

2. Install the dependencies:

```bash
npm install
```

3. Set up your MongoDB connection. Create a `.env` file in the root directory and add your MongoDB connection string:

```env
MONGODB_URI=mongodb://127.0.0.1:27017/yourdbname
```

4. Run the server:

```bash
npm start
```

The server will start running on `http://localhost:3000`.

## Project Structure

```
.
├── models
│ └── user.js
├── public
│ └── stylesheets
│ └── index.css
│ └── javascripts
│ └──index.js
├── views
│ ├── index.ejs
│ ├── read.ejs
│ └── edit.ejs
├── app.js
├── package-lock.json
├── package.json
└── README.md
```

### `models/user.js`

This file defines the user schema and model for MongoDB using Mongoose.

### `public/stylesheets/style.css`

This file contains the CSS styles for the application.

### `views/index.ejs`

This file contains the EJS template for the homepage.

### `views/read.ejs`

This file contains the EJS template for displaying the list of users.

### `views/edit.ejs`

This file contains the EJS template for editing a user.

### `app.js`

This file contains the main application code, including route definitions and middleware setup.

## Routes

### GET `/`

Renders the homepage.

### GET `/read`

Renders the list of users.

### POST `/create`

Creates a new user and redirects to `/read`.

### GET `/delete/:id`

Deletes a user with the given ID and redirects to `/read`.

### GET `/edit/:id`

Renders the edit form for the user with the given ID.

### POST `/edit/:id`

Updates the user with the given ID and redirects to `/read`.

## Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

## License

This project is licensed under the MIT License.
```

You can customize the content, especially the sections that refer to your MongoDB URI and other specifics that might differ based on your setup. Make sure to replace `yourusername` with your actual GitHub username and `yourdbname` with your actual database name.