JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
about 2 months ago0 views
👨‍💻Programming

1. Backend (Node.js + Express.js)

// server.js
const express = require('express');
const mongoose = require('mongoose');
const app = express();

app.use(express.json());

// Connect MongoDB
mongoose.connect('mongodb://127.0.0.1:27017/testDB')
  .then(() => console.log("DB Connected"))
  .catch(err => console.log(err));

// Simple Schema
const User = mongoose.model('User', {
  name: String
});

// API Route
app.get('/users', async (req, res) => {
  const users = await User.find();
  res.json(users);
});

// Start Server
app.listen(5000, () => console.log("Server running"));

2. Frontend (React.js)

// App.js
import React, { useEffect, useState } from 'react';

function App() {
  const [users, setUsers] = useState([]);

  useEffect(() => {
    fetch('http://localhost:5000/users')
      .then(res => res.json())
      .then(data => setUsers(data));
  }, []);

  return (
    <div>
      <h2>User List</h2>
      {users.map((u, i) => (
        <p key={i}>{u.name}</p>
      ))}
    </div>
  );
}

export default App;
← Back to timeline