JavaScript Project – Movie Rating System
Full Stack Web Development Courses with Real-time projects Start Now!!
Program 1
{
"name": "movie-ratings-console",
"version": "1.0.0",
"description": "Console-based Movie Ratings and Analytics System in Node.js",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"mysql2": "^3.14.1"
}
}Program 2
const mysql = require('mysql2');
const pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: 'root',
database: 'movie_rating_system'
});
module.exports = pool.promise();Program 3
const db = require('./db');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function showMenu() {
console.log("\n--------------- Movie Ratings System ------------");
console.log("1. Add Actor");
console.log("2. Add Movie");
console.log("3. Add Rating");
console.log("4. Show Top Movies");
console.log("5. Show Top Actors");
console.log("0. Exit");
console.log("---------------------------------------------------------")
rl.question("Choose an option: ", handleChoice);
}
async function handleChoice(choice) {
switch (choice.trim()) {
case '1':
rl.question("Enter Actor ID: ", id => {
rl.question("Enter Actor Name: ", async name => {
await db.execute("INSERT INTO actors (actor_id, actor_name) VALUES (?, ?)", [id, name]);
console.log("Actor added.");
showMenu();
});
});
break;
case '2':
rl.question("Enter Movie ID: ", id => {
rl.question("Enter Title: ", title => {
rl.question("Enter Release Year: ", year => {
rl.question("Enter Category ID: ", async catId => {
await db.execute("INSERT INTO movies (movie_id, title, release_year, category_id) VALUES (?, ?, ?, ?)", [id, title, year, catId]);
console.log("Movie added.");
showMenu();
});
});
});
});
break;
case '3':
rl.question("Enter Rating ID: ", ratingId => {
rl.question("Movie ID: ", movieId => {
rl.question("User ID: ", userId => {
rl.question("Rating (0–10): ", rating => {
rl.question("Date (YYYY-MM-DD): ", async date => {
await db.execute("INSERT INTO ratings VALUES (?, ?, ?, ?, ?)", [ratingId, movieId, userId, rating, date]);
console.log("Rating added.");
showMenu();
});
});
});
});
});
break;
case '4':
const [movies] = await db.query(`
SELECT m.title, ROUND(AVG(r.rating), 2) as avg_rating
FROM movies m
JOIN ratings r ON m.movie_id = r.movie_id
GROUP BY m.movie_id, m.title
ORDER BY avg_rating DESC
LIMIT 5
`);
console.log("\n Top Rated Movies:");
movies.forEach(m => console.log(`${m.title} - ${m.avg_rating}`));
showMenu();
break;
case '5':
const [actors] = await db.query(`
SELECT a.actor_name, ROUND(AVG(r.rating), 2) as avg_rating
FROM actors a
JOIN movie_actor ma ON a.actor_id = ma.actor_id
JOIN ratings r ON ma.movie_id = r.movie_id
GROUP BY a.actor_name
ORDER BY avg_rating DESC
LIMIT 5
`);
console.log("\n Top Actors:");
actors.forEach(a => console.log(`${a.actor_name} - ${a.avg_rating}`));
showMenu();
break;
case '0':
console.log("Exiting...");
rl.close();
break;
default:
console.log("Invalid option!");
showMenu();
}
}
showMenu();Program 4
{
"name": "movie-ratings-console",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "movie-ratings-console",
"version": "1.0.0",
"dependencies": {
"mysql2": "^3.14.1"
}
},
"node_modules/aws-ssl-profiles": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz",
"integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==",
"license": "MIT",
"engines": {
"node": ">= 6.0.0"
}
},
"node_modules/denque": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.10"
}
},
"node_modules/generate-function": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz",
"integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==",
"license": "MIT",
"dependencies": {
"is-property": "^1.0.2"
}
},
"node_modules/iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-property": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz",
"integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==",
"license": "MIT"
},
"node_modules/long": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz",
"integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==",
"license": "Apache-2.0"
},
"node_modules/lru-cache": {
"version": "7.18.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"node_modules/lru.min": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.2.tgz",
"integrity": "sha512-Nv9KddBcQSlQopmBHXSsZVY5xsdlZkdH/Iey0BlcBYggMd4two7cZnKOK9vmy3nY0O5RGH99z1PCeTpPqszUYg==",
"license": "MIT",
"engines": {
"bun": ">=1.0.0",
"deno": ">=1.30.0",
"node": ">=8.0.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wellwelwel"
}
},
"node_modules/mysql2": {
"version": "3.14.1",
"resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.14.1.tgz",
"integrity": "sha512-7ytuPQJjQB8TNAYX/H2yhL+iQOnIBjAMam361R7UAL0lOVXWjtdrmoL9HYKqKoLp/8UUTRcvo1QPvK9KL7wA8w==",
"license": "MIT",
"dependencies": {
"aws-ssl-profiles": "^1.1.1",
"denque": "^2.1.0",
"generate-function": "^2.3.1",
"iconv-lite": "^0.6.3",
"long": "^5.2.1",
"lru.min": "^1.0.0",
"named-placeholders": "^1.1.3",
"seq-queue": "^0.0.5",
"sqlstring": "^2.3.2"
},
"engines": {
"node": ">= 8.0"
}
},
"node_modules/named-placeholders": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz",
"integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==",
"license": "MIT",
"dependencies": {
"lru-cache": "^7.14.1"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/seq-queue": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz",
"integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q=="
},
"node_modules/sqlstring": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz",
"integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
}
}
}
You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

