Posts

Showing posts with the label mongoose

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