https://github.com/serhatpolat/crudizer-core-server
Backend of crudizer-core (Node.js, Express.js, MongoDB, cors, dotenv)
https://github.com/serhatpolat/crudizer-core-server
api backend cors dotenv expressjs javascript mongodb nodejs
Last synced: 2 months ago
JSON representation
Backend of crudizer-core (Node.js, Express.js, MongoDB, cors, dotenv)
- Host: GitHub
- URL: https://github.com/serhatpolat/crudizer-core-server
- Owner: SerhatPolat
- License: mit
- Created: 2024-02-03T21:03:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-08T10:13:28.000Z (over 2 years ago)
- Last Synced: 2024-02-08T17:38:03.030Z (over 2 years ago)
- Topics: api, backend, cors, dotenv, expressjs, javascript, mongodb, nodejs
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# crudizer-core
crudizer-core is a fullstack CRUD web app kickstarter which one is includes common essentials:
- E2E data listing (w/ pagination) (Mongo database => Node.js backend => Nuxt 3 & Axios API requests => UI)
- Ready to use E2E base64 image dataflow
- Create/Update/Delete transactions for items
- Item detail page & related logics
- Ready to use UI for essentials (w/ responsive styling and config based color usage)
### Set up environment variables
Set `MONGODB_URI` variable on `.env` file (which one is included in .gitignore):
- `MONGODB_URI` - Your MongoDB connection string. If you are using [MongoDB Atlas](https://mongodb.com/atlas) you can find this by clicking the "Connect" button for your cluster.
### Set up dynamic parts
```js
// In my Mongo database, 'company' is my db name and 'products' is my collection name. You should update that parts with your db and collection namings.
const itemsCollection = client.db("company").collection("products");
```
```js
// When you adding new endpoints you just need to change endpoint itself ("/api/items") and itemsCollection value.
// NOTE: If you want to add a different behavior to your new endpoint of course you should change other things
app.post("/api/items", async (req, res) => {
try {
const newItem = req.body;
const result = await itemsCollection.insertOne(newItem);
res.status(201).json({ message: "Item created successfully" });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
```
### About get requests
There is 3 options for read transactions of items. You can use the right one according to your needs for different situations.
- Get all items together
- Get items with a pagination structure
- Just get one item with id
_This is **backend** repo of crudizer-core, you can reach to **frontend** from here:_ [crudizer-core-client](https://github.com/SerhatPolat/crudizer-core-client)
Install dependencies:
```bash
npm install
```
Run server:
```bash
node app.js
```