大佬教程收集整理的这篇文章主要介绍了node.js – 如何在Cloud9中连接MongoDB?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
var MongoClient = require("mongodb").MongoClient; var port = process.env.PORT; var ip = process.env.IP; MongoClient.connect("mongodb://"+ip+":"+port+"/test",function(error,db){ if(!error){ console.log("We are connected"); } else{ console.dir(error); //Failed to connect to [127.4.68.129:8080] } });
输出:
Running Node Process Your code is running at 'http://demo-project.alfared1991.c9.io'. Important: use 'process.env.PORT' as the port and 'process.env.IP' as the host in your scripts! [Error: Failed to connect to [127.4.68.129:8080]]
下面是从Node.js homepage修改为使用两个环境变量的Hello world示例.
var http = require('http'); http.createServer(function (req,res) { res.writeHead(200,{'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(process.env.PORT || 1337,process.env.IP || '127.0.0.1');
以上是大佬教程为你收集整理的node.js – 如何在Cloud9中连接MongoDB?全部内容,希望文章能够帮你解决node.js – 如何在Cloud9中连接MongoDB?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。