Installing Web Server

This section will help you walk through the minimum step by step to run Kindie web server


After install Node.js and npm Package Manager at previous step, now you have to install some tools, dependencies to run the Kindie web server:

Step 1: Open Kindie project by Visual Studio Code:

Note: You can toogle terminal by hot keys Ctrl + `

Step 2: Install Sails.js using npm Package Manager:

npm -g install sails
Sails.js is a small framework build on top of Express and Node.js framework. You can refer full document about SailsJs here:

https://sailsjs.com/get-started

Step 3: Install others npm Package Manager:

npm install

Step 4: Run MongoDB server
To start MongoDB, run mongod.exe. For example, from the Command Prompt:

C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe

This starts the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.

You can refer full document about MongoDB here:

https://docs.mongodb.com/v3.6/installation/


Step 5: Config database and settings web server
If you need to test on dev eviroment, modify the config here:

config > env > development.js

5.1 Modify the database configuration:

      // ssl: true,
      adapter: 'sails-mongo',
      host: '127.0.0.1', // defaults to `localhost` if omitted 
      port: 27017, // defaults to 27017 if omitted 
      user: '', //optional
      password: '', //optional
      database: 'kindiedb' // or omit if not relevant

5.2 Modify socket config ( For realtime chatbox mobile application): replace socket config with your domain:

sockets: {

    /***************************************************************************
    *                                                                          *
    * Uncomment the `onlyAllowOrigins` whitelist below to configure which      *
    * "origins" are allowed to open socket connections to your Sails app.      *
    *                                                                          *
    * > Replace "https://example.com" etc. with the URL(s) of your app.        *
    * > Be sure to use the right protocol!  ("http://" vs. "https://")         *
    *                                                                          *
    ***************************************************************************/
    onlyAllowOrigins: [
      'https://kindie.zinisoft.net',
      'http://localhost:1337',
],

5.3 Modify port: default port for development environment is 1337, you can change what you want

      port: 1337,
Note: For production, you have to config the same things but with this file: config > env > production.js

Step 6: Config email server to send email (config > email.js)

        service: "Mailgun", 
	auth: {
		user: "no-reply@yourdomain",
		//pass: "key-xxx"
		pass: "yourpassword"
	},
	templateDir: "api/emailTemplates",
	from: "no-reply@yourdomain",
	testMode: false,
	ssl: true

By default we are using Mailgun service, you need to register an account via https://www.mailgun.com/ then input the username/password here. Mailgun supports us to send with 10,000 free emails and a 100 free validations every month.
Step 7: Run the app
If you need to run on dev mode, from terminal console Visual Studio Code, run:

        sails lift

will run sails project on port 1337 by default, the web server will use the config is located at env > development.js.

If you get the log message like this, congratulation, you installed successfully the Kindy Web server.

For run web server on production mode, please modify the config at config > env > production.js (if no file create new) then run:

 
forever start app.js --prod
Note: Before run on production, you can run test production by command sails lift --prod

Note: On production server, You can create .env file and define also all the configurations via .env file at root folder:

MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
MONGO_USER=""
MONGO_PASSWORD=""
MONGO_DB_NAME="kindiedb"
SAILS_BASE_URL="http://localhost:1337"
SAILS_PORT="1337"
MAIL_SERVICE="Mailgun"
MAIL_AUTH_USER="no-reply@yourdomain.com"
MAIL_AUTH_PASSWORD="xxx"
MAIL_FROM="no-reply@yourdomain.com"
PATH_FOLDER="/var/www/web-kindie/"

Have fun!


Leave a Reply