Prerequisites: installed nodejs and sailsjs
Create necessary directories
Open up terminal and write:
mkdir example-blog cd example-blog/
Create sails backend
sails new example-blog-backend
We could lift sails now, but if we’d like to use MongoDB instead of using built-in ‘sails-disk’, we could install MongoDB right now.
Install MongoDB
cd example-blog-backend/ npm install sails-mongo --save
Now you have to say sails to use MongoDB. For that you have to modify two files: config/connections.js and config/models.js. Open up your editor and go to:
config/connections.js
myMongodbServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
// user: '...',
// password: '...',
database: 'example-blog-db'
}
config/models.js
connection: 'myMongodbServer'
If you make “sails lift” now, MongoDB creates itself database with name you gave it in connections.js, in current case ‘example-blog-db’
Lift sails
Go to folder example-blog-backend/ and:
sails lift
Go to address http://localhost:1337/ in your browser and you could see sails welcome-page.
We didn’t generate API now, because its more reasonable to take care about authentication before it. In next post we install ‘Waterlock’ for authentication and then generate API.