Example output
Example 1: <!DOCTYPE html>
<html>
<head>
<title>Ecommerce Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Cart</a></li>
<li><a href="#">Login</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h1>Featured Products</h1>
<ul>
<li>
<img src="product1.jpg" alt="Product 1">
<h2>Product 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.</p>
<button>Add to Cart</button>
</li>
<li>
<img src="product2.jpg" alt="Product 2">
<h2>Product 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.</p>
<button>Add to Cart</button>
</li>
<li>
<img src="product3.jpg" alt="Product 3">
<h2>Product 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.</p>
<button>Add to Cart</button>
</li>
</ul>
</section>
<section>
<h1>Product Catalog</h1>
<form>
<label for="search">Search:</label>
<input type="text" id="search" name="search">
<button>Search</button>
</form>
<form>
<label for="category">Category:</label>
<select id="category" name="category">
<option value="">All</option>
<option value="1">Category 1</option>
<option value="2">Category 2</option>
<option value="3">Category 3</option>
</select>
<label for="price">Price:</label>
<input type="range" id="price" name="price" min="0" max="100" step="10" value="0">
<button>Filter</button>
</form>
<ul>
<li>
<img src="product4.jpg" alt="Product 4">
<h2>Product 4</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.</p>
<button>Add to Cart</button>
</li>
<li>
<img src="product5.jpg" alt="Product 5">
<h2>Product 5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.</p>
<button>Add to Cart</button>
</li>
<li>
<img src="product6.jpg" alt="Product 6">
<h2>Product 6</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus.</p>
<button>Add to Cart</button>
-------------------------------------------------------------------------------------------------------------
Example 2:
// Import necessary libraries and modules
const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const cors = require('cors');
const mongoose = require('mongoose');
const Note = require('./models/note');
// Create the express app and configure middleware
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(
session({
secret: 'your secret key',
resave: false,
saveUninitialized: true
})
);
app.use(cors());
// Connect to the database
mongoose.connect('mongodb://localhost:27017/notes', {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log('Connected to the database');
}).catch((err) => {
console.log(err);
});
// Define routes for the application
app.get('/', (req, res) => {
res.send('Welcome to the Notes Application');
});
app.post('/api/notes', async (req, res) => {
const { title, content } = req.body;
const note = new Note({
title,
content
});
await note.save();
res.json({
success: true,
message: 'Note saved successfully'
});
});
app.get('/api/notes', async (req, res) => {
const { q } = req.query;
let notes;
if (q) {
notes = await Note.find({
$text: {
$search: q
}
});
} else {
notes = await Note.find();
}
res.json(notes);
});
app.get('/api/notes/:id', async (req, res) => {
const { id } = req.params;
const note = await Note.findById(id);
if (!note) {
res.status(404).json({
success: false,
message: 'Note not found'
});
}
res.json(note);
});
app.put('/api/notes/:id', async (req, res) => {
const { id } = req.params;
const note = await Note.findById(id);
if (!note) {
res.status(404).json({
success: false,
message: 'Note not found'
});
}
const { title, content } = req.body;
note.title = title || note.title;
note.content = content || note.content;
await note.save();
res.json({
success: true,
message: 'Note updated successfully'
});
});
app.delete('/api/notes/:id', async (req, res) => {
const { id } = req.params;
const note = await Note.findById(id);
if (!note) {
res.status(404).json({
success: false,
message: 'Note not found'
});
}
await note.delete();
res.json({
success: true,
message: 'Note deleted successfully'
});
});
// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});