Posts

How to Use Sequelize ORM In Node

Image
Prerequisites Node MySql What Is Sequelize? As mentioned on the sequelize site, sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication and more. Sequelize follows  SEMVER . It supports Node v6 and above to use ES6 features. Project Structure  |---------  config                |--------- db.js |--------- controllers                |--------- memberController.js |--------- models                |--------- member.js |--------- routes                |-------- members.js |--------- views                 | |------- partials                 |              |------- header.ejs                 |              |------- footer.ejs                 |                 |------ home.ejs                 |------ edit.ejs |---------  app.js |--------- package.json Project Setup Le

Upload And Download File In Node

Image
Here we will use multer middleware for uploading file . Click the link to know what is  multer . Setup The Project Folder create a new folder using console/terminal. open console/terminal type mkdir followed by the folder name you want to give. change to that folder by typing cd  folder name. Setup Node For The Project now type npm init on console/terminal. the  npm init  will create a  package.json  file.But we can create it manually too. just open the folder and  add a new file  and name it  package.json  and then we can structure it the same way as its been structured when using  npm init . the package.json will look like this. now we will install packages for our project using npm install followed by package names we want to install. the following packages will be installed express ejs body-parser multer mongoose . this will generate a folder name node_modules which will contain all the node packages. after the pac

How To Apply Form Validation In Node.

Image
Image by Gerd Altmann from Pixabay Open the console and create a new folder named validations by typing command mkdir followed by folder name. Change to the new folder by typing command cd validations.  Now setup node project by typing npm init. This will auto generate a package.json file in folder. now add a add.js file and then open the package.json and in " scripts" write "start":"app.js". The package.json will look like this.  Now type npm install followed by package name. We install the following packages: express ejs body-parser express-validator. Now add a folder name views . And in it make a new file names register.ejs. app.js var express = require ( 'express' ); var bodyParser = require ( 'body-parser' ); var path = require ( 'path' ) var {check,validationResult} = require ( 'express-val

CURD operations in node.

Image
Image by StartupStockPhotos from Pixabay Setup Node On System    If you dont have node installed on your system then you can download it   click here After installing the node on system.Open cmd and type node-v .It will give node version like this        Setup MongoDB On System  If you dont have mongodb installed on your system then you can download it from  here    Follow the installation instruction given there.   Now setup our node project  Open cmd type mkdir and give directory name. Now your directory to that using cd directory name which we created.  Now type npm init -y . this will make a package.json file in your folder. Now we will npm  install package which we will use in our project.And all these will be shown in package.json. The npm packages we will install here are express,mongoose,body-parser,ejs.          This is how package.json looks               A little info about packages we using body-parser will contain