Intro to Sails.js
Вставка
- Опубліковано 28 вер 2024
- sailsjs.com
Sails.js makes it easy to build custom, enterprise-grade Node.js apps, from top to bottom. It uses an MVC architecture developers are familiar with from frameworks like Ruby on Rails. Finally, it's especially good at API-driven applications and realtime features like chat, realtime dashboards, and online games.
Website: sailsjs.com
Github: github.com/bal...
Docs: sailsjs.com/doc...
Twitter: / sailsjs
Gitter: gitter.im/bald...
StackOverflow: stackoverflow.c...
Looking for more videos? Check out @ponzicoders follow-ups:
• Introduction to Node a...
sooo many frameworks ,soo many choices, my brain is about to explode
I would definitely recommend Sails.js, the genius of it is just unfounded. Easily configurable with API's such as Angular, Backbone and Knockout. I've used Sails.js in a wide array of my projects in the development world and lured more the my fair share of developers into the Sails.js framework.
Raptus that feedback just got my mind set. I'm just starting a huge project and betting for Nodejs (hope i won't regret), and took a lot of time looking for a good framework (was already doing things myself with express, but it's too tiring)
shipper66 Sounds like a first world problem. One that I like having.
David Hesson I think I made my choice. It's clojure/clojurescript all the way. So I am at peace now.
@shipper66 How did that end up? I've heard it's a lot of work.
I saw them in UA-cam's "Recommended for you" section (which was a nice change since it never recommends anything of use on any other day). Just finished the most recent video this morning, and it's a nice beginning to a series, but it aims at the complete node-newbie. Still a step forward though and good reference ;)
Hi Linh-- great question! You can- take a look at the hidden .app.js file in your project. Check out "Guide: Deployment" in the wiki.
Hey Amit, working on it. UA-cam won't let me post links, but I created a gist in the meantime (it doesn't hash the password, or use a salt or anything-- the version I bundle in new Sails projects will). But hopefully it will give you an idea of how it works. You can find it on the Sails wiki on github.
Good stuff Mike. Will definitely check it out.
Thanks- needless to say, I wasn't expecting the kind of response this video got! My 3AM, red-eyed demo video doesn't really seem worthy of the wonderful, supportive community that has grown around Sails since I recorded it.
I'll definitely put some more time into the next one :)
Thumbs up for sublime!
Really really cool! Thanks alot!
when too high of a resolution actually becomes a bad thing :)
What extension did you use to get those JSON pretty prints.
this not work for me
socket.on('message',function (message) {
console.log("Got message:",message);
});
:V
Is this production ready?
Not a comment about sails, but about your screencast. It's not very video or screen friendly. You should shoot for fonts "look" at the scale of 1024x768
Bring back Deployd. We need an HTML dashboard for entering data. Something like Parse but local and open source.
tip: reduce resolution when making screencasts
nice
jsonview, chrome store
Shuffling between screens too fast really distracts your audience ...
step 1) Look at this video and get all pumped up about sails js
step 2) try the code and fail miserably
step 3) give up on sails for the time being
You should definitely update this video. Given this tutorial is probably the first impression that most people will get of Sails js, you are most likely loosing a lot of enthusiastic people in a matter of 14 minutes.
Tiago Ferreira great point.
+Tiago Ferreira (Tiagojdferreira) Exactly. I'm sitting here, "oh that's pretty cool." Then a note pops up, informing me that isn't how Sails works anymore. +Mike McNeil I've been fussing with the Platzi site for 10 minutes, and I can't figure out how to get it to surrender any content. It's time to update your homepage. Watching this "5 minute" video turned out to be a seriously disappointing 30 minute adventure. Sails is starting to smell of abandon-ware.
+Mike McNeil Then you should probably change the github page to link to that instead of this.
+Tiago Ferreira (Tiagojdferreira) Honestly man, if you fire up the sails generator, the webpage literally says how to do this
the matter at hand is "if I follow this tutorial", and if you do you will not succeed. Could be that sails is a great solution for backend, but the truth is that I tried this tutorial before anything else, and since I was looking for a technical solution, I was not convinced. Having an outdated tutorial in your main page gives the idea that development in this project is in a halt and that the community is not very active. Because of those reasons, back in May I opted for some other solution at that time. If I have some free time in the next few weeks I will give sails another try :) ***** maybe update github.com/balderdashy/www.sailsjs.org/blob/master/views/homepage.ejs to show that instead ?
Why is an outdated video on the homepage of the framework ?
what is this link bro ! it's full of wired chinees shit
The fact a "Modern" framework in 2016 is featuring a video from 2013 on its home page as the "Getting Started" video says a lot about evolution imo ...
Just look at their git repo.... that's the real indicator of evolution and fossyness.
Great tutorials, the principles very much remain the same, however the files have very much changed come v0.10 and configuring has changed a bit. Think this should be further updated for the new version (Unless I'm mistaken and there is already a new tutorial released).
Your video tutorial is instructive, but it's be nice if you could present it with larger fonts.
+Kiffin Gish Yeah... I had trouble reading it too
Why are you only using half the screen? If you're going to promote your product, the least you could do is give us a full screen demo.
Much of the functionality of Sails reminds me of what can be done with CouchDB and the JS lib PouchDB. CouchDB and PouchDB have real-time replication and can do socket-like updating. I just thought the comparison between Sails and CouchDB + PouchDB might be an interesting comparison.
Coming from Express, Sails is much easier. Great work! I had spent 2 hours and I have got a complete webpage with blogarticles and a little shoutbox. It works like a charm.
This is great stuff man. Bout to start digging in tomorrow morning. I have a little pet project I want to be working on in my spare time, and this seems like the perfect framework for me to work with. Good work man, I hope you stay with it because it looks extremely promising.
Creating models with GET requests is bugging me--that's a violation of HTTP. But at least you have the option to do it the right way :) Can you disable create, update, and delete over GET?
yes you can - go look at config/controllers.js
EDIT: My bad it's config/blueprints.js not config/controllers.js
I wanted to complain about creating models with GET requests, too. Is this design flaw fixed by now?
hit8run I think you're missing the point of shortcuts.
lanswipe It is mentioned that sails offers JSON scaffolding instead of rails like html scaffolding because html scaffolding cannot be used in production and the JSON version can be used. If it is meant to be used for production then this "shortcut" should be sticking to REST standards. That's my point. Otherwise a shortcut is not really a shortcut and you have to spend additional time fixing something that could be right from the start IMHO
hit8run Not only have you misunderstood the point of shortcuts you also seem to have not read the config files. The config file for blueprints clearly states(pastebin.com/1pYfDacW - look at line 106) that you should turn shortcuts off in production. Also it's worth noting that even with shortcuts on you can still interact with the API in a RESTful manner.
Hello Mike, I come from Rails world and I'm working on my very first own production app based on node and react. I came here by a chance and I gotta say I'm amazed. Thank you for doing such awesome stuff!
can this be updated please? I really hope it is by version 0.10 How do you expect ppl to get excited for your stuff if the docs are outdated. 'findAll' no longer exits, it's 'find' and how the heck do you do where queries via a post request? I'm sure sails is good and the docs will improve.
1) @ 5:50 - 6:10 For me, socket.request is undefined in the 'socket' variable after setting value, e.g. socket = io.connect('localhost:1337');
Any ideas why? I see sailsjs.com/documentation/reference/web-sockets/socket-client/io-socket-request exists still.
2) @ 6:49 - 6:59 "This is not necessary in current versions of sails." which variable exists to refer to the existing connection? How can I replicate showing console.log messages on message received with current versions of sails?
I tried to use sails like 2 years ago (when this RESTful buzz was everywhere), but the thing that stopped me was that I did not want to use sessions, since they completely break the REST style and couldn't find a module, so went back to Express.
I'd greatly appreciate it if you could tell me the best way of getting the ability to handle real time events with sails. Do I need a front-end framework to handle the socket.io or is it possible to do with .ejs? This confuses me a lot as the sailsjs documentation states it's a real-time MVC framework, but I can't seem to understand how to implement this real-time ability.
Cheers.
My company has been using it in production for over a year-- we're working on some quantitative benchmarking, but really you're mainly just looking at a pretty standard Express and Socket.io setup underneath the covers. At scale, you'll want to configure Redis for your session and socket store so you can create a cluster of instances. I'd recommend a Node.js-oriented PaaS like Modulus or Nodejitsu for deployment.
Hi Chris,
Sails.js controllers are actually just Express middleware. And Sails' defers to Express for routing. That lets us take advantage of its excellent code base, stability, and community.
Sails.js exists to add some additional structure, support for WebSockets, an adaptable ORM similar to Rails' active record, and some other convenience features like css/js/template bundling.
You can find more about what Sails.js does in the wiki on github.
-mm
Hi Thomas--
I'm planning on doing a follow-up screencast to demo what's new in 0.9 soon, and I'll be sure and spend some more time covering a few ACL/auth use cases then. Thanks for the feedback!
@Ponzicoder is working on a deeper dive into a basic, authenticated CRUD app from a rails developer's perspective.
I've been slammed the last couple of months and haven't had the opportunity to really go hit the conference circuit-- we did a few talks locally, which was really fun. Looking forward to getting the chance to get out and show Sails.js to the world this summer :) If you've got any recommendations, I'd love to hear them!
We've speced out what an after-like syntax would look like (see issue #176). To hit parity with 'before', you can use policies (express middleware) to achieve the same effect. Re: can-- looking forward to seeing how it goes! You can modify Sails' API in the controllers to match whatever you need on the front-end.
POSTing to findAll to get all users. Makes me cringe.
RESTfulness? Zero.
Got a little something for that we aren't being too vocal about right now, but check out our Github and look for "Mast". We're looking to partner with the Angulars, Embers, and Marionettes of the world to build that part out for us. Otherwise papa bear is never going to get any sleep ^_^
Im actually working on a related issue today-- however, I think what you're experiencing may have been solved in a recent patch. What version of sails are you running?
Yep! Newest version lets you enable and disable all three kinds of API blueprints in your controllers.js config, as well as adding an API prefix (e.g. /api/v2)
Hi Pankaj- try it in 0.8.94 and you should see the appropriate error message. Are you talking to a socket connection on the same server or on another domain?
I'd be happy to-- working on a couple of sequels; one for controllers and one for adapters. Anybody else have an example of Mast they can release as open-source?
PonziCoder just released a great series of videos that go on a deeper dive, especially into how to use controllers and how Sails differs from Rails
One big gotcha is that the "Content-type" header has to be "application/json". If that doesn't work, please let us know in the google group. Thanks!
Ah it's not deep merging the config. It's fixed in development on GitHub and will be fixed in 0.9.5- thanks for identifying the problem!
Do we have to configure database in config/connection.js before accessing urls?
thanks! If you feel like experimenting with associations, check out particlebanana's fork on github-- we're getting close!
Hi Theeraphol- check out "sailscasts" for more videos using the latest version of Sails (0.9.7 as of today)
Hi
after writing the same code which u did 7:37
i am getting error mentioned below.
can you please help
debug - authorized
sails/lib/router/interpreter.js:74
return expressContext.res.send('Error retrieving session: ' + err, 500);
^
TypeError: Cannot read property 'res' of undefined
at sails/lib/router/interpreter.js:74:25
at /sails/node_modules/connect/lib/middleware/session/memory.js:57:7
at process._tickCallback (node.js:415:13)
Hi Mike,
I love Sails, but you kind of breezed over the authentication. As I'm a bit of a Node noobie, that was a tad bit jarring for me. Could you point me in the right direction to get user authentication working?
Really having fun playing with this but getting confused once I start adding controllers :P Are there any other tutorials or repos on Github that demonstrate some of the core concepts? Perhaps anything that uses Mast?
La comodidad de los flujos de trabajos hace más profesional el día a día de cualquier desarrollador, esta es una gran muestra!, simplemente genial!.
I can't seem to get clustering working. It just complains that the port is already in use but commenting that out just causes it to hang. Any tutorials for clustering a sails app?
I am new and i didn't understand any of it....like why what...so??
when you are going to make a tutorial of sail.js with graphql
I tried to install Sails.js in my computer(it's a Windows 7),with "sudo npm install sails",but the command "sudo" doesn't work,but I have installed Node.js.Could you help me?
Hey guys, this looks really interesting. But I couldn't find any information on authentication on your wiki. Could you please add some barebone code for authenticating users?
The request parameter doesn't work in Postman "where" : { } "limit": 3
works in the browser but not in postman, any ideas?
Hi there, great point! I don't know how much you've played w/ Node.js in the past, but this is the de facto standard way of doing things right now.
The future of Sails.js is bigger than server restarts. We're building a fast, modern web framework, where you write less code and do more awesome stuff. We're not in 1.0 yet, but I think we're off to a pretty good start.
That said, a dynamic module loader is coming. In the mean time, you can use forever -w to watch your filesystem for changes.
This is 2020 and my love for Sails is huge. Thanks for creating Sails
If only you kept the screencasting to a specific region on the screen...
Otherwise, it's awesome!
Awesome, some people from roket.mx was trying to sell us similar stuff with nodejs+angularjs.
Esta genial, excelente trabajo!! :)
sorry! I'm a screencast noob. Thanks for the feedback.
Can you tell me how the services work in Sails. I don't see any documentation about it.
Wow youtube recommended I watch this video and its exactly what I've been looking for!
That sounds awesome. Sails kicks ass and you guys keep up the good work!
I was struggling in creating apis in Express. This is exactly what I need now.
I can't read the code. Any chance of uploading a higher res version?
You don't need sudo on Windows. npm install sails should work.
Check out the irc if you get stuck :)
This looks pretty neat, the only thing that troubled me is the fact that you can create model objects with GET requests, is there a way to only allow for post, put, delete to modify the database?
yes
check out the associations branch!
Great stuff, I'll be using it for my next project :)
Great stuff, I'll be using it for my next project :)
That sounds like a great idea!
Good work, I especially like the policies settings
Whats that little alien on top of chromes window?
A user profile. You can make them in the settings.
Each user has separate history, separate bookmarks etc
I can't find them, can you create a list ? Thanks
Thanks! And don't worry :)
Seems this video is not valid for current sailjs version no more?
Ex. after I did generate user, I can't do findAll
Blueprints are disabled.
I really want to use sails, but early on I'm not able to get the populate() query working with the sails-mysql adapter. Wondering if you you could give me some pointers?
Department:
attributes: {
id: {
type: 'integer',
primaryKey: true
}
courses: {
collection: 'Courses',
via: "departmentId"
}
},
Courses
attributes: {
id: {
type: "integer",
primaryKey: true
},
departmentId: {
model: "Departments"
}
},
I removed all irrelevant fields. I believe this is the correct setup, but populate always returns an empty array. There seems to be very little existing support for this problem online, so it is incredibly discouraging...
Change:
departmentId: {
model: "Departments"
}
for this:
departmentId: {
model: "Department"
}
Oh that was a typo when I typed in the UA-cam comment. My model was originally defined as "Departments".
My populate query was:
Departments.find().populate("courses")
albert275 try then without the id attr:
Departments
attributes: {
courses: {
collection: 'Courses',
via: "departmentId"
}
},
Courses
attributes: {
departmentId: {
model: "Departments"
}
}
Waterline will generate an unique id for you.
To ask this kind of questions -> stackoverflow.com :)
albert275 www.jlmonteagudo.com/2014/06/rest-api-development-with-sails-js/ worked like a charm
Cool but can it do russian doll caching?
Thanks for the tip!
the intro music is .........
Perfect tutorial. Now, off to github.
Can I use nodemon with sails ?
Very cool for real-time apps
coooool stuff ;)
GREAT Sails!
Yeah postman is nice
How did you run socket.io from web browser console?
+Leung Wong That's using sails.io.js, a client-side library that comes with newly generated Sails apps. It's a light wrapper for the socket.io client that augments it with an HTTP abstraction layer that allows it to talk to the routes in your Sails app, and receive "comet" (socket) events+data from sails.sockets.* methods on the backend.
Thanks!
I've been using Sails professionally now for real, deployed websites, and it's really nice. Hopefully the associations get added soon, as I really want more people to use this terrific framework.
cant get sockets to work........................................................
tried for days, if anyone has done this with reversed proxies (nginx) please educate me. I've set the path on client to the correct proxy, and since accessing localhost/PROXY gives a "/" request to the nodejs server, i haven't specified a path on the serverside.. still doesn't work -_-
sciencefyll I'm able to get connected, but then:
failed: Error during WebSocket handshake: Unexpected response code: 400
sciencefyll And yes NGINX is SSL based, the connection between nodejs local server and local nginx is http. because ssl is not needed here.. but BLAH ANGER and stuff