Sure, here are five examples of Node.js syntax:
- Defining a variable:
const message = "Hello, World!";
- Using built-in modules:
const fs = require('fs');
- Creating a function:
function greet(name) {
console.log(`Hello, ${name}!`);
}
- Using arrow function:
const add = (a, b) => {
return a + b;
};
- Using asynchronous file reading:
const fs = require('fs');
fs.readFile('example.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});
These examples demonstrate basic Node.js syntax for variable declaration, module import, function creation, arrow functions, and asynchronous file reading using the fs
module.