Slip5:Create a Node.js file that writes an HTML form, with an upload field.

 const http = require('http');


http.createServer(function (req, res) {

    // When form is submitted
    if (req.url === '/upload' && req.method === 'POST') {
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.end("<h2>File uploaded successfully!</h2>");
    }
    else {
        // Show form
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.end(`
            <h2>Upload File</h2>
            <form action="/upload" method="post" enctype="multipart/form-data">
                Select File:<br><br>
                <input type="file" name="fileupload"><br><br>
                <input type="submit" value="Upload">
            </form>
        `);
    }

}).listen(3000);

console.log("Server running at http://localhost:3000/");

Comments

Popular posts from this blog

Slip 11: Write node js application that transfer a file as an attachment on web and enables browser to prompt the user to download file using express js.

Slip 7 Create a node js file named main.js for event-driven application. There should be a main loop that listens for events, and then triggers a callback function when one of those events is detected.

Slip 1(a) Write an Angular 13 application addition of two numbers using ng-init, ng-model & ng-bind. And also demonstrate ng-show, ng-disabled, ng-click directives on button component.