An anonymous secret-sharing app I built with Node.js, Express, Passport.js, PostgreSQL, and EJS. It handles local and Google OAuth login, lets users submit secrets anonymously, and displays them in a rotating carousel. Uses bcrypt for password hashing, connection pooling for the database, and Material Design-inspired UI.
- Features
- Visual Demo
- Folder Structure
- How It Works
- Dependencies
- Installation & Usage
- Database Configuration
- API Endpoints
- Customization & Extensions
- Contributing
- Authentication: Email/password and Google OAuth2
- Anonymous sharing: Submit and update secrets without exposing identity
- Secrets feed: Carousel showing all submitted secrets
- Security: Hashed passwords, sessions, and SQL injection-safe queries
- UI: Responsive, Material Design-style layout
- Performance: PostgreSQL connection pooling and efficient session usage
- Validation: Server-side input checks with error messages
- Responsive: Works on desktop and mobile
secrets-app/
├── index.js # Main server file with routes & auth
├── package.json # Dependencies & scripts
├── .env # Environment variables (gitignored)
├── views/
│ ├── home.ejs # Landing page
│ ├── login.ejs # Login form
│ ├── register.ejs # Registration form
│ ├── secrets.ejs # Rotating secrets carousel
│ ├── submit.ejs # Secret submission form
│ └── partials/
│ ├── header.ejs # Navigation header
│ └── footer.ejs # Footer with attribution
└── public/
└── css/
└── styles.css # Material Design-inspired styling
- Users can register with email/password or sign in with Google OAuth2
- Passwords are hashed using bcrypt with salt rounds
- Sessions store only user ID for security and efficiency
- Passport.js handles authentication strategies
- Users must be authenticated to view or submit secrets
- Each user can have one secret that can be updated
- Secrets are stored anonymously in PostgreSQL
- Submit form shows user's current secret for easy editing
- Displays all submitted secrets in random order
- Auto-rotates every 5 seconds with smooth transitions
- Manual navigation with previous/next buttons
- Keyboard navigation support (arrow keys)
- Mobile-responsive controls
- Connection pooling with
pg.Poolfor database efficiency - Parameterized queries prevent SQL injection
- Session management with secure cookies
- Input validation and error handling
- Graceful shutdown with proper cleanup
Core Dependencies:
express- Web frameworkejs- Templating enginepg- PostgreSQL client with connection poolingbcrypt- Password hashingpassport- Authentication middlewarepassport-local- Local authentication strategypassport-google-oauth2- Google OAuth2 strategyexpress-session- Session managementcookie-parser- Cookie parsing middlewaredotenv- Environment variable management
Development:
nodemon- Development server with auto-restart
- Node.js v16 or higher
- PostgreSQL v12 or higher
- Google OAuth2 credentials (for Google sign-in)
- npm or yarn package manager
- Clone the repository
git clone https://github.com/Avaneesh40585/Secrets-App.git
cd Secrets-App- Install dependencies
npm install- Environment configuration
-
Required environment variables:
Variable Description Example PG_USERPostgreSQL username postgresPG_HOSTDatabase host localhostPG_DATABASEDatabase name secretsPG_PASSWORDDatabase password mypasswordPG_PORTPostgreSQL port 5432GOOGLE_CLIENT_IDOAuth2 client ID your-client-id.googleusercontent.comGOOGLE_CLIENT_SECRETOAuth2 client secret your-client-secretSESSION_SECRETSession encryption key very-long-random-stringPORTApplication port 3000 -
Create a
.envfile in the root directory:
PG_USER=your_database_user
PG_HOST=localhost
PG_DATABASE=secrets
PG_PASSWORD=your_database_password
PG_PORT=5432
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
SESSION_SECRET=your_very_long_random_session_secret
PORT=3000- Database setup
# Create the Database first if not created already
createdb -U postgres todo-list
# Then connect to PostgreSQL and run the queries.sql file
psql -U postgres -d todo-list -f queries.sql- Google OAuth Setup
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth2 credentials
- Add
http://localhost:3000/auth/google/secretsas authorized redirect URI
- Start the application
nodemon index.js- Access the app
Open http://localhost:3000 in your browser
The application uses a single PostgreSQL table:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255), -- NULL for OAuth users
secret TEXT, -- User's submitted secret
provider VARCHAR(32) DEFAULT 'local' -- 'local' or 'google'
);Key Features:
- Auto-incrementing ID as primary key
- Unique email constraint
- Flexible password field (NULL for OAuth users)
- Provider field to distinguish authentication methods
- Text field for secrets with no length limit
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Home page with registration/login options |
GET |
/login |
Login form |
GET |
/register |
Registration form |
POST |
/login |
Authenticate user (redirects to /secrets) |
POST |
/register |
Create new user account |
| Method | Endpoint | Description |
|---|---|---|
GET |
/auth/google |
Initiate Google OAuth2 flow |
GET |
/auth/google/secrets |
OAuth2 callback URL |
| Method | Endpoint | Description |
|---|---|---|
GET |
/secrets |
View rotating carousel of all secrets |
GET |
/submit |
Secret submission form (shows current secret) |
POST |
/submit |
Create or update user's secret |
GET |
/logout |
Logout and destroy session |
- Add email verification during signup to confirm user accounts.
- Implement password reset via email tokens for account recovery.
- Introduce categories and filters so users can browse secrets by topic.
- Add a like/reaction system to let users interact with secrets anonymously.
- Build an admin dashboard for moderating flagged or inappropriate content.
- Apply rate limiting to prevent spam and abuse.
- Include a dark mode toggle for better user experience.
- Add export functionality so users can download their own secrets.
- Implement a notification system to alert users
I welcome contributions! Here's how to get started:
First, click the Fork button at the top right of this page to create a copy of this repository on your own GitHub account.
Then, clone your forked repository to your local machine:
# Replace 'YOUR-USERNAME' with your actual GitHub username
git clone [https://github.com/YOUR-USERNAME/Secrets-App.git](https://github.com/YOUR-USERNAME/Secrets-App.git)
# Move into the project directory
cd Secrets-Appgit checkout -b feature/amazing-feature- Follow existing code style and conventions
- Add comments for complex logic
- Test your changes thoroughly
git commit -m "Add amazing feature: description of what it does"git push origin feature/amazing-featureGo to your forked repository on GitHub. You should see a prompt to create a Pull Request. Click "Compare & pull request" to submit your changes for review.
Start sharing secrets anonymously today!
