1 / 14

Node js

This code and ppt for the nodejs intro

Viraj3
Download Presentation

Node js

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to the Node js and NPM

  2. Introduction to Node js Developers who have worked over the JavaScript cannot deny from the efficiency of JavaScript and its advanced frameworks. The multiple frameworks today support the highly used language, which ensures better development, engaging UI and better functionality. NodeJS is an open-source JavaScript platform used for app and web development services, which is built on the Chrome V8 JavaScript engine. It is also fast, scalable and a powerful web server. NodeJS is an open-source JavaScript platform used for app and web development services, which is built on the Chrome V8 JavaScript engine. It is also fast, scalable and a powerful web server.

  3. Introduction to NPM The full form of NPM is Node Package Manager NPM is the world's largest Software Library (Registry). NPM is also a software Package Manager and Installer. The registry contains over 800,000 code packages. Open-source developers use npm to share software. Many organizations also use npm to manage private development.

  4. Use of Node js The full form of NPM is Node Package Manager NPM is the world's largest Software Library (Registry). NPM is also a software Package Manager and Installer. The registry contains over 800,000 code packages. Open-source developers use npm to share software. Many organizations also use npm to manage private development.

  5. Installation The full form of NPM is Node Package Manager sudo apt-get update After the completeing the update of ubuntu packages ,Write the command : sudo apt install nodejs

  6. The NPM ( Node Package Manager ) is installed .Check the version with the command : node -v node --version After the completeing the update of ubuntu packages ,Write the command : sudo apt install npm

  7. The NPM ( Node Package Manager ) is installed .Check the version with the command : npm -v npm --version

  8. File upload and Find ASCII value In this program we have to find the ASCII (American Standard Code for Information Interchange) for the content in TXT file. In the code the main focus is on taking the TXT file from the user and convert into the array and then into the ASCII value.

  9. Code const express = require('express')//extra package installer const upload = require('express-fileupload')//package installer for the uploading file var fs = require('fs'); const app = express()//object for the package installer app.use(upload())//variable for uploading the file console.log("Listening on port number:3000")//printing the port number on server app.get('/', (req, res) => { res.sendFile(__dirname + '/project.html') }) //send file html file to local host app.post('/', (req, res) => { const file = req.files.mfile fs.readFile(file.name, function (error, data) { res.write(data); var D = data.toString().split(""); res.write('\n\n'); for (let i = 0; i < D.length; i++) { res.write('\n' + D[i]); res.write('\n' + D[i].charCodeAt() + '\n'); } res.end() }) }) //for reading the file and converting the txt into array and then into ASCII value and display in the local host through html file. app.listen(3000)

  10. Html code <h1>File Upload</h1> <form method="POST" action="/" enctype="multipart/form-data"> <input type="file" name= "mfile" required/> <input type="submit" value="Upload"/> </form>

  11. Install NPM "mysql" and create database and show on local host In this program we have to first install mysql and connect with NPM and then create database in the Nodejs

  12. Code var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "viraj", password: "Password123#@!" }); con.connect(function(err) { if (err) throw err; console.log("Connected!........."); con.query("CREATE DATABASE dbd", function (err, result) { if (err) throw err; console.log("Database created"); }); con.query("use dbd", function (err, result) { if (err) throw err; console.log("Database used"); });

  13. var sql = "CREATE TABLE Emp_info (Id INT,name VARCHAR(255), address VARCHAR(255),Mob_no INT)"; con.query(sql, function (err, result) { if (err) throw err; console.log("Table created"); }); var ins = "INSERT INTO Emp_info (Id, name, address,Mob_no) VALUES ?"; var values = [ [1,'John', 'Highway',56649864], [2,'Peter', 'Lowstreet',46563656], [3,'Amy', 'Apple',46164517], [4,'Hannah', 'Mountai',74523654], [5,'Michael', 'Valley',63514785] ]; con.query(ins, [values], function (err, result) { if (err) throw err; console.log("Number of records inserted: " + result.affectedRows); }); if (err) throw err; con.query("SELECT * FROM Emp_info", function (err, result, fields) { if (err) throw err; console.log(result); }); });

  14. Html code <!DOCTYPE html> <html> <head> <title>Document</title> </head> <body> <form action="/" method="POST"> <table type="text" name="firstname" ></table> </form> </body> </html>

More Related