ClickCease

Node.js Programming

1. Basics

2. Creating a Simple Server


const http = require('http');
const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello, World!n');
});
server.listen(3000, '127.0.0.1', () => {
    console.log('Server running at http://127.0.0.1:3000/');
});

3. File System Operations

4. Modules

5. NPM Commands

6. Asynchronous Programming

  • Callback Example:
    
    
    function fetchData(callback) {
        setTimeout(() => {
            callback('Data fetched');
        }, 1000);
    }
    fetchData((data) => {
        console.log(data);
    });
    
  • Promises:
    
    
    const fetchData = () => {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('Data fetched');
            }, 1000);
        });
    };
    fetchData().then(data => console.log(data));
    
  • Async/Await:
    
    
    const fetchData = async () => {
        return 'Data fetched';
    };
    const getData = async () => {
        const data = await fetchData();
        console.log(data);
    };
    getData();
    

7. Express.js Framework

8. Debugging

9. Commonly Used Modules

10. Tips

Download Elysium Spark Note

Facebook
X
LinkedIn
Pinterest
WhatsApp