Posts

Showing posts with the label mongodb

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...

How to Upload and Download Files in Node.js (Express & Multer)

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.Js 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 w...

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 pack...