This example shows how to develop our first application step by step, assuming you already have Sails installed and a project created.
$ sails generate controller hello
api/controllers/HelloControllers.js
and add the hello
method to it.module.exports = {
hello : function (req, res) {
var myName = 'Luis';
return res.view('hello' , {name : myName});
}
}
views
named hello.ejs
with the following HTML:<html>
<head></head>
<body>
<p>Hello {{}}.</p>
</body>
</html>
config/routes.js
that calls the hello
method in the HelloController
controller.'GET /' : 'HelloController.hello',
Now we have implemented all the code needed for this example. Let's try it:
$ sails lift
Open the browser and type http://localhost:1337
. If it's not coming up, check the URL in the sails lift
output. The port may be different.
You should see the following output:
Hello Luis