如何使用Node。js在服务器端

时间:2022-11-20 15:12:21

I am new to Node.js. Are we able to connect mysql with Node.js directly or we need any npm installation to perform it and if i am using nosql database like MongoDB then how can we connect it with node.js.

我是新手。我们能把mysql和Node连接起来吗?js直接或我们需要任何npm安装来执行它,如果我使用的是nosql数据库,比如MongoDB,那么我们如何将它与node.js连接起来。

2 个解决方案

#1


2  

Any time you need functionality in a Node.js project, look at NPMjs.org. There's a vibrant array of add on modules for Node.js that can enable you to accomplish all kinds of things quickly.

在节点中任何需要功能的时候。js项目,看看NPMjs.org。在Node模块上有一个充满活力的add on模块。能让你快速完成所有事情的js。

You can use the node-mysql module to connect to MySQL from Node.js.

可以使用node-mysql模块从Node.js连接到MySQL。

npm install mysql

You can use node-mongodb-native to connect to MongoDB from Node.js.

您可以使用node-mongodb-native从Node.js连接到MongoDB。

npm install mongodb

#2


1  

You need database driver to connect to any database like mysql,mongodb, neo4j etc. I haven't used mysql but quick search on www.npmjs.org reveals mysql https://npmjs.org/package/mysql as first options so go with it for start. For mongodb the most popular choices are mongodb https://npmjs.org/package/mongodb if you prefer to work with documents yourself or choose mongoose https://npmjs.org/package/mongoose if your prefer ORM. So just add them in your package.json dependencies and do npm install

你需要数据库驱动程序来连接任何数据库,比如mysql、mongodb、neo4j等等。对于mongodb,最受欢迎的选择是mongodb https://npmjs.org/package/mongodb,如果你喜欢使用ORM,你可以选择mongoose https://npmjs.org/package/mongodb。所以只要把它们添加到你的包中。json依赖项并执行npm安装

 {
   "dependencies" : {
     "mongodb"   :  "*",
     "mysql" :  "*",
     "mongoose " :  "*"
    }
 }

#1


2  

Any time you need functionality in a Node.js project, look at NPMjs.org. There's a vibrant array of add on modules for Node.js that can enable you to accomplish all kinds of things quickly.

在节点中任何需要功能的时候。js项目,看看NPMjs.org。在Node模块上有一个充满活力的add on模块。能让你快速完成所有事情的js。

You can use the node-mysql module to connect to MySQL from Node.js.

可以使用node-mysql模块从Node.js连接到MySQL。

npm install mysql

You can use node-mongodb-native to connect to MongoDB from Node.js.

您可以使用node-mongodb-native从Node.js连接到MongoDB。

npm install mongodb

#2


1  

You need database driver to connect to any database like mysql,mongodb, neo4j etc. I haven't used mysql but quick search on www.npmjs.org reveals mysql https://npmjs.org/package/mysql as first options so go with it for start. For mongodb the most popular choices are mongodb https://npmjs.org/package/mongodb if you prefer to work with documents yourself or choose mongoose https://npmjs.org/package/mongoose if your prefer ORM. So just add them in your package.json dependencies and do npm install

你需要数据库驱动程序来连接任何数据库,比如mysql、mongodb、neo4j等等。对于mongodb,最受欢迎的选择是mongodb https://npmjs.org/package/mongodb,如果你喜欢使用ORM,你可以选择mongoose https://npmjs.org/package/mongodb。所以只要把它们添加到你的包中。json依赖项并执行npm安装

 {
   "dependencies" : {
     "mongodb"   :  "*",
     "mysql" :  "*",
     "mongoose " :  "*"
    }
 }