在开发第一个MERN博客过程中遇到的概念

91 阅读1分钟

Mongoose和MongoDB什么区别?

两者关系类似于 Node.js 和 exporess 或 Koa。后者都是基于前者之上进行功能封装的库。很多开发中都会使用现成的 ODM,否则使用起来就是直接调用 mongodb 的底层接口。 Mongodb是数据库本身,而Mongoose是Mongodb的对象建模工具。

为什么我使用npm i初始化了项目却在后面能用yarn add为项目添加依赖?

image.png

image.png image.png

Yarn and npm are both package managers for Node.js, and they serve a similar purpose of managing dependencies in your project. While they perform similar functions, they are separate tools with some differences in their features and behavior.

To answer your question, you can use yarn to add a new package to a project that was initially set up using npm because both package managers operate on the same package.json file, which keeps track of your project's dependencies. This means that if you have an existing project that was initialized using npm, you can switch to using yarn or vice versa without any issues.

The reason why you can use yarn after initializing a project with npm is not because they are both included in Node.js itself. Rather, it's because the package.json file and the node_modules directory (where project dependencies are stored) are independent of the package manager you choose to use. As long as you have Node.js installed on your computer, you can use either yarn or npm to manage your project's dependencies.

When you add a new package using yarn or npm, the package manager will update the package.json file and download the required package into the node_modules directory. Other developers working on the project can then use the same package manager to install the dependencies based on the information in the package.json file.

So, in summary, you can use yarn to add a new package to a project initialized with npm because they both work with the same underlying package.json file and node_modules directory. It's not because they are included in Node.js itself, but rather because they are separate tools that can manage dependencies in a Node.js project.

在我的项目node_modules中找不到yarn的包但是根目录下有yarn.lock文件,说明我的项目在之前用过npm i yarn添加过yarn执行文件

image.png