Posts

How to Setup a Flask Project in Python: Step-by-Step Guide

Image
Prerequisite Python What Is Flask ? Flask is a lightweight Web framework written in Python. It is developed by  Armin Ronacher. Flask is based on the Werkzeug WSGI toolkit and Jinja2 template engine Setup Development Environment First Install Virtualenv In Python virtualenv  is a virtual python environment builder.virtualenv    is used to manage python packages for different projects. Using virtualenv allows you to avoid installing python packages globally which could break system tools or other projects. Install the virtualenv using the following command.This command needs administrator privileges # pip install virtualenv After installing the virtualenv . Make Folder create new folder using the following command  # mkdir flaskdemo change to the current created directory/folder # cd flaskdemo Create a Virtual Environment for Flask In Folder Now we will create a virtualenv .  The commands below will c...

How to Upload Files Using AJAX in Node.js(Express)

Introduction In this blog, we will see how to upload an image file using AJAX. We will use the FileReader API to read the selected file, send the file data to the server via AJAX, and handle and save it as an image on the server side. Project Structure |--------- views |--------- demo.ejs |--------- app.js |--------- package.json Setup Folder Open your command prompt and create a new folder using the following command: mkdir upload Navigate into the newly created folder: cd upload Setup Node In Folder Initialize the Node.js environment by running: npm init -y This command creates a package.json file indicating that Node is initialized in the folder. Install Packages Install the required packages for building the application (Express, Body-Parser, EJS, and jQuery): npm install body-parser ejs express jquery Add Folders and Views Create a new folder named views in your project root, and inside it, create a file na...

How to Use AJAX with Node.js, Express, and MongoDB

Project Structure |-------------- models |-------------- task.js |-------------- public |-------------- data.js |-------------- routes |-------------- taskroute.js |-------------- views |-------------- demo.ejs |-------------- app.js |-------------- package.json Setup The Folder To create a folder, open your command prompt and type: mkdir ajax Change to the folder by typing: cd ajax Setup Node In Folder On the console, initialize your Node.js project: npm init -y This creates a package.json file indicating that Node is initialized in the folder. Install Packages Install the required packages for building the application: npm install body-parser express ejs mongoose jquery Models Create a new folder named models , add a file named task.js , and insert the following code: var mongoose = require('mongoose'); var taskSchema = new mongoose.Schema({ task:{ ...

How to Import CSV File Data into MongoDB Using Node.js and Express

Setup Folder Open your command prompt and create a new folder using the following command: mkdir csv After creating the folder, change into it by running: cd csv Setup Node In Folder Initialize the Node.js environment in your project: npm init -y This generates a package.json file containing the metadata for your application. Install Packages Install the required packages for handling CSV parsing, routing, template rendering, and file uploads: npm install csvtojson express ejs mongoose multer body-parser Add New Folders Create the following folders in your project root directory: models public views Models Folder (csv.js) Add a new file inside the models folder named csv.js to define your MongoDB collection schema: var mongoose = require('mongoose'); var csvSchema = new mongoose.Schema({ FirstName:{ type: String }, LastName:{ type: String }, SSN:{ type: S...

Adding Searching Functionality In Node

In this article we see how we can enable the searching of data from server in our node application. Setup The Folder  a) Make a new folder using command prompt.Type the following command. mkdir search b) change to the new folder cd search Setup Node In Folder For setting up node we type the following command npm init -y it will initialize the node in our project. And we get a package.json file in our folder. Which  means node is initialized in our folder. Install Packages Now we install the packages which will be required for building the application. npm install express ejs body-parser mongoose. Add New Folder models views models - this will contain our schema of collections(table). views - will contain the ejs pages.   Model Add new file in folder name it data.js Views Add 2 folders a)pages b)partial In partial folder add 2 new files header.ejs and footer.ejs header.ejs footer.ejs In pages add ho...

Hashing Password With Bcrypt In Node

Image
Image by Jae Rue from Pixabay Introduction In this article we will be using the bcryptjs javascript library for hashing and compare password.Here we will build a simple api fore register and login.when we will hash the password when user register and then compare that password with hash when they login. What is bcrypt ? bcrypt is a  password hashing function  designed by  Niels Provos  and David Mazières, based on the  Blowfish  cipher, and presented at  USENIX  in 1999.Besides incorporating a  salt  to protect against  rainbow table  attacks, bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to  brute-force search  attacks even with increasing computation power. What is hashing ?  Hashing is a one way function (well, a mapping). It's irreversible, you apply the secure hash algorithm and you cannot ge...

How to Use Sequelize-CLI to Create Tables and Relationships in Node.js

Introduction In this article, we will explore how to use Sequelize-CLI for creating database tables and setting up powerful relationships between multiple tables using foreign keys in Node.js and MySQL. Project Structure |--------- config |--------- config.json |--------- models |--------- index.js |--------- department.js |--------- emp.js |--------- migrations |--------- [timestamp]-create-department.js |--------- [timestamp]-create-emp.js |--------- seeders |--------- app.js |--------- package.json Setup The Node Project Let's begin by initializing our workspace: Open your console and create a new directory: mkdir seqlcli Navigate into that directory: cd seqlcli Initialize the Node.js project by running: npm init This will prompt you for basic project metadata like name, version, and author, generating a package.json file. Install P...