Installation
Setup
- Create a folder using the command
mkdir server - Navigate to the folder using the command
cd server - we're installing node men globally so we have access to installing or running our node through a live service so it refreshes every time we save
npm i -g nodemon
npm i express body-parser bcrypt cors dotenv gridfs-stream multer multer-gridfs-storage helmet morgan jsonwebtoken mongoose- The
expresslibrary is used as the web framework for our Node.js application. body-parseris used to parse the request body from incoming HTTP requests and extract data from it.bcryptis used to securely hash passwords and other sensitive information to store in the database.corsis used to handle Cross-Origin Resource Sharing, allowing requests from different domains to access the resources on our server.dotenvis used to manage environment variables, keeping sensitive information such as database credentials outside of version control.gridfs-streamis used to stream files to and from MongoDB, allowing us to handle large files efficiently.multerandmulter-gridfs-storageare used to handle file uploads, allowing us to store uploaded files either locally or in MongoDB using gridfs-stream.helmetis used to add security-related HTTP headers to the responses, making the Express app more secure.morganis used for logging HTTP requests and responses, making it easier to debug and analyze the application.jsonwebtokenis used for authentication, allowing us to securely transmit information such as user IDs between the client and server.mongooseis used as an Object Document Mapping (ODM) library for MongoDB, allowing us to interact with the database using JavaScript objects.
-
npm init -yto create a package.json file -
Now open the package.json file and add the following scripts to it:
type: "module",so now you can use import and export in your code