Posts

Showing posts with the label mongodb

How to Use AJAX with Node

Image
Project Structure                |-------------- models        |                          |-------------- task.js                                    |         |-------------- public        |                          |-------------- data.js        |            |--------------- routes         |                          |-------------- taskroute.js        |         |--------------- views        |                          |-------------- demo.ejs        |         |--------------- app.js Setup The Folder To create a folder, open the command prompt and type cmd mkdir followed by the folder name    # mkdir ajax Change to the folder by typing the cmd cd followed by the folder name  # cd ajax  Setup Node In Folder On the console, type the below command   # npm init -y This will create a package.json file, Which means that node is initialised in the folder. the package.json will look like this  Install Pack

Import CSV File Data Into MongoDB In Node

Image
Setup Folder Open the command prompt and create new folder using the following command followed by folder name. mkdir csv After creating the folder.Change to that folder by using the following command cd csv Setup Node In Folder To setup node in folder use the following command npm init -y This will setup node in our folder.And  after the execution of this command you will see package.json file which means node is initialised. This package.json file will contain the metadata related to our project. The package.json will look like this Install Packages Now we have to install packages to be used to build our application. To install packages we use the following command followed by package name.  npm install csvtojson express ejs mongoose multer body-parser  After installation package.json will look like this Add New Folders Add few new folders in our project folder  models public views Models Folder Add new file

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 home.ejs file.

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

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