Friday, April 21, 2017

SailsJS untuk Pemula - part I

Pertama-tama mari kita install SailsJS-nya pake npm ajjah. Silahkan jalankan perintah ini :

'npm i sails -g --no-optional'
Naah... disitu -g flag buat global directory, trus --no-optional biar g' usah nginstall dependencies di windows (soalnya skrg lg make windows 7)
Silahkan ditunggu beberapa menit biar packagenya kedownload ke repo local kita. Tar klu udah selese, kita bisa nyoba pake command 'sails -h' yg hasilnya kek gini :
Naaah... berikutnya kita ngebuat project sails baru pake perintah ini 'sails new myFirstSails'
myFirstSails itu nama folder project kita tar klu udah jadi.......
Struktur folder utama project sailsnya kyk gini :
Terus folder model dan controllernya ada didalam folder api kyk gini :
Naah...terakhir klu projectnya mau di run, pake perintah 'sails lift'

Port defaultnya 1337... Kalu dibuka tampilannya seperti ini :

Cooool...... Cukup sekian dl untuk part pertama... :D

Wednesday, April 19, 2017

Nodejs Express Generator

Next, let's install express-generator by running this command "npm i express-generator -g --no-optional" 

I'm ruunning nodejs in windows 7, so I need that --no-optional flag in order to prevent fsevent error message :D

After installing express-generator, we can see it's folder inside node-modules like this 
Next.... Let's test our express generator by running 'express -h' like this :

Ok... Let's create our first express-generator project 'express myFirstExpGen'
After running that command, we can see our directory content like this :
Btw,, actually we can specify view engine by using --v=pug|jade|ejs and etc. We also can specify css engine by using --c=less|stylus|sass|compass.... In this post I'm using default engine so it will be jade for view and plain css for css.

Next, let's run 'npm install' for installing project dependencies..

Last... Let's run our express, for windows, we can use this command :
'set DEBUG=projectDirName:* & npm start'

And then open localhost:3000 
Yeeei.... btw.... www file inside of  bin directory is our starting project file, and that file loads app.js.

Aaaand in this default project, we already have /users so if we open the page we will gonna see something like this :
It's content :