// Load HTTP module
const http = require("http");
// Create HTTP server and listen to requests on port 8000
http.createServer((request, response) => {
// Send the response body as "Hello World"
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8000);
// Output: Server running at http://localhost:8000/
console.log('Server running at http://localhost:8000/');
bashCopy code
# Initialize a new Node.js project
npm init
# Install express framework
npm install express
console.log('Hello, World!');
let name = 'Your Name';
const birthYear = 1990;
console.log(name, birthYear);
let number = prompt("Enter a number: ");
if (number > 0) {
console.log("The number is positive.");
} else if (number < 0) {
console.log("The number is negative.");
} else {
console.log("The number is zero.");
}
// Let's make a 10x10 multiplication table
for (let i = 1; i <= 10; i++) {
for (let j = 1; j<= 10; j++){
console.log( i + " * " + j + " is " + i*j )
}
}
function add(a, b) {
return a + b;
}
console.log(add(3, 4)); // Outputs: 7
let books = ['Book1', 'Book2', 'Book3'];
for (let i = 0; i < books.length; i++) {
console.log(books[i]);
}
let person = {
firstName: 'John',
lastName: 'Doe',
age: 30
};
console.log(person.firstName); // Outputs: John
console.log(person.lastName); // Outputs: Doe
console.log(person.age); // Outputs: 30
// Defining an object with a method
const mathOperations = {
add: function(a, b) {
return a + b;
},
multiply: function(a, b) {
return a * b;