DeveloperBreeze

Execute Shell Command using 'child_process' module

// Import 'child_process' module
const { exec } = require('child_process');

// Execute 'ls -l' command
exec('ls -l', (error, stdout, stderr) => {
  // Check for errors
  if (error) {
    console.error('Error:', error);
    return;
  }

  // Log the result
  console.log('Result:', stdout);
});

Related Posts

More content you might like

Tutorial

Build a Custom Rate Limiter in Node.js with Redis

const userKey = req.headers['x-api-key'] || req.ip;
const key = `rate_limit:${userKey}`;

You can now:

Apr 04, 2025
Read More
Tutorial
javascript css +1

Building a Real-Time Chat Application with WebSockets in Node.js

const socket = io();

const messageForm = document.getElementById('chat-form');
const messageInput = document.getElementById('message');
const messagesList = document.getElementById('messages');

messageForm.addEventListener('submit', (e) => {
    e.preventDefault();
    const message = messageInput.value;
    socket.emit('chatMessage', message);
    messageInput.value = '';
});

socket.on('chatMessage', (message) => {
    const li = document.createElement('li');
    li.textContent = message;
    messagesList.appendChild(li);
});
node server.js

Aug 03, 2024
Read More
Code
php

JWT Token Creation and Verification in Node.js using 'jsonwebtoken'

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Simple HTTP Server in Node.js

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!