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
express
library is used as the web framework for our Node.js application. body-parser
is used to parse the request body from incoming HTTP requests and extract data from it.bcrypt
is used to securely hash passwords and other sensitive information to store in the database.cors
is used to handle Cross-Origin Resource Sharing, allowing requests from different domains to access the resources on our server.dotenv
is used to manage environment variables, keeping sensitive information such as database credentials outside of version control.gridfs-stream
is used to stream files to and from MongoDB, allowing us to handle large files efficiently.multer
andmulter-gridfs-storage
are used to handle file uploads, allowing us to store uploaded files either locally or in MongoDB using gridfs-stream.helmet
is used to add security-related HTTP headers to the responses, making the Express app more secure.morgan
is used for logging HTTP requests and responses, making it easier to debug and analyze the application.jsonwebtoken
is used for authentication, allowing us to securely transmit information such as user IDs between the client and server.mongoose
is used as an Object Document Mapping (ODM) library for MongoDB, allowing us to interact with the database using JavaScript objects.
-
npm init -y
to 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