RT,就是这个软件Robomongo,挺好用的,网站介绍是Native and cross-platform
RT,就是这个软件Robomongo,挺好用的,网站介绍是Native and cross-platform
在Ubuntu服务器中端中执行如下命令可以安装4.x版本的node.js
- curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
- sudo apt-get install -y nodejs
如果想安装5.x版本的node.js可以执行
- curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
- sudo apt-get install -y nodejs
编译安装就不介绍了。
在Sails.js中,默认使用的是本地的一个数据库localDiskDb,我们在项目中如果想使用数据库MongoDB的话,需要自己手动配置,首先是config/connections.js文件,我们需要将我们想使用的数据库通过配置文件添加进去。入红字部分
- /**
- * Connections
- * (sails.config.connections)
- *
- * `Connections` are like "saved settings" for your adapters. What's the difference between
- * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic--
- * it needs some additional information to work (e.g. your database host, password, user, etc.)
- * A `connection` is that additional information.
- *
- * Each model must have a `connection` property (a string) which is references the name of one
- * of these connections. If it doesn't, the default `connection` configured in `config/models.js`
- * will be applied. Of course, a connection can (and usually is) shared by multiple models.
- * .
- * Note: If you're using version control, you should put your passwords/api keys
- * in `config/local.js`, environment variables, or use another strategy.
- * (this is to prevent you inadvertently sensitive credentials up to your repository.)
- *
- * For more information on configuration, check out:
- * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html
- */
- module.exports.connections = {
- /***************************************************************************
- * *
- * Local disk storage for DEVELOPMENT ONLY *
- * *
- * Installed by default. *
- * *
- ***************************************************************************/
- localDiskDb: {
- adapter: 'sails-disk'
- },
- /***************************************************************************
- * *
- * MySQL is the world's most popular relational database. *
- * http://en.wikipedia.org/wiki/MySQL *
- * *
- * Run: npm install sails-mysql *
- * *
- ***************************************************************************/
- someMysqlServer: {
- adapter: 'sails-mysql',
- host: 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS',
- user: 'YOUR_MYSQL_USER',
- password: 'YOUR_MYSQL_PASSWORD',
- database: 'YOUR_MYSQL_DB'
- },
- /***************************************************************************
- * *
- * MongoDB is the leading NoSQL database. *
- * http://en.wikipedia.org/wiki/MongoDB *
- * *
- * Run: npm install sails-mongo *
- * *
- ***************************************************************************/
- MongodbServer: {
- adapter: 'sails-mongo',
- host: 'localhost',
- port: 27017,
- // user: 'username',
- // password: 'password',
- database: 'catgood'
- },
- /***************************************************************************
- * *
- * PostgreSQL is another officially supported relational database. *
- * http://en.wikipedia.org/wiki/PostgreSQL *
- * *
- * Run: npm install sails-postgresql *
- * *
- * *
- ***************************************************************************/
- somePostgresqlServer: {
- adapter: 'sails-postgresql',
- host: 'YOUR_POSTGRES_SERVER_HOSTNAME_OR_IP_ADDRESS',
- user: 'YOUR_POSTGRES_USER',
- password: 'YOUR_POSTGRES_PASSWORD',
- database: 'YOUR_POSTGRES_DB'
- }
- /***************************************************************************
- * *
- * More adapters: https://github.com/balderdashy/sails *
- * *
- ***************************************************************************/
- };
到这里,数据库并没有切换,我们还需要设置config/models.js
- /**
- * Default model configuration
- * (sails.config.models)
- *
- * Unless you override them, the following properties will be included
- * in each of your models.
- *
- * For more info on Sails models, see:
- * http://sailsjs.org/#!/documentation/concepts/ORM
- */
- module.exports.models = {
- /***************************************************************************
- * *
- * Your app's default connection. i.e. the name of one of your app's *
- * connections (see `config/connections.js`) *
- * *
- ***************************************************************************/
- connection: 'MongodbServer',
- /***************************************************************************
- * *
- * How and whether Sails will attempt to automatically rebuild the *
- * tables/collections/etc. in your schema. *
- * *
- * See http://sailsjs.org/#!/documentation/concepts/ORM/model-settings.html *
- * *
- ***************************************************************************/
- migrate: 'safe'
- };
其中的connection后面的字段就是connection.js中配置的MongoDB的名称,然后migrate这里我们使用safe模式,其实这里有三种模式可以选择,如果注释掉这一行,启动sails lift的时候会提示。
到这里我们配置文件已经配置了,需要用npm来添加支持组件了。
- npm install sails-mongo
到此为止,MongoDB的安装就完成了。
很久不搞web了,学点儿新东西。最近打算学习node.js,做个小项目,找了下node.js的框架,感觉比较喜欢Sails.js,但是国内的Sails.js的资料实在是少之又少,于是乎,决定自己把Sails的教程整理下,也不知道能学到啥样,能做出啥东西来,一点儿点儿来吧,奶牛Sails.js折腾现在开始。
1.Sails.js需要node.js的支持,所以先安装Node.js。过程不详述。
2.安装Sails.js
- npm -g install sails
3.使用Sails.js建立Sails.js项目
- sails new nenewTestProject
4.启动Sails.js项目
- cd nenewTestProject
- sails lift
这时候如果sails正常运行会看到如下提示
- info: Starting app...
- info:
- info: .-..-.
- info:
- info: Sails <| .-..-.
- info: v0.12.1 |\
- info: /|.\
- info: / || \
- info: ,' |' \
- info: .-'.-==|/_--'
- info: `--'-------'
- info: __---___--___---___--___---___--___
- info: ____---___--___---___--___---___--___-__
- info:
- info: Server lifted in `C:\Users\Nenew\nenewTestProject`
- info: To see your app, visit http://localhost:1337
- info: To shut down Sails, press <CTRL> + C at any time.
- debug: --------------------------------------------------------
- debug: :: Sat Feb 27 2016 11:34:28 GMT+0800 (中国标准时间)
- debug: Environment : development
- debug: Port : 1337
- debug: --------------------------------------------------------
至此,Sails.js已经安装运行成功,我们可以通过http://localhost:1337对Sails.js的默认页面进行访问。