E N D
Introduction to the Node js and NPM
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.
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.
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.
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
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
The NPM ( Node Package Manager ) is installed .Check the version with the command : npm -v npm --version
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.
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)
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>
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
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"); });
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); }); });
Html code <!DOCTYPE html> <html> <head> <title>Document</title> </head> <body> <form action="/" method="POST"> <table type="text" name="firstname" ></table> </form> </body> </html>