You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- FIxed spelling, grammar and broken link issues with the Getting Started documentation.
- Ensured that Keystone is capitalised everywhere in the docs
- Set Mongoose docs link to V4
Copy file name to clipboardExpand all lines: docs/Getting Started/Setting-Up/part-1.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,17 @@
2
2
3
3
## Introduction
4
4
5
-
If you want to jump right in to a working keystone codebase, check out our [quick start guide](/getting-started/yo-generator), which walks you through using our generator to get a keystone codebase up and running quickly. This tutorial will walk you through setting up a project, looking at what the core parts of keystone are and how to set them up.
5
+
If you want to jump right in to a working Keystone codebase, check out our [quick start guide](/getting-started/yo-generator), which walks you through using our generator to get a Keystone codebase up and running quickly. This tutorial will walk you through setting up a project, looking at what the core parts of Keystone are and how to set them up.
6
6
7
7
This guide assumes you are familiar with using npm to install packages, and javascript as a language.
8
8
9
9
We're going to be tackling this in three parts.
10
10
11
11
Part 1 (this one here) will focus on installation and setting up our `keystone.js` file, which launch our app.
12
12
13
-
[Part 2](/getting-started/setting-up/part-2) will detail building keystone models and setting up your database.
13
+
[Part 2](/getting-started/setting-up/part-2) will detail building Keystone models and setting up your database.
14
14
15
-
[Part 3](/getting-started/setting-up/part-3) will go through setting up routes with keystone to serve both database information as well as website pages.
15
+
[Part 3](/getting-started/setting-up/part-3) will go through setting up routes with Keystone to serve both database information as well as website pages.
16
16
17
17
[Part 4](/getting-started/setting-up/part-4) will get a us a `POST` endpoint which we can use to post data to.
18
18
@@ -21,20 +21,20 @@ Before we start, make sure you have [node](nodejs.org) and [mongo](https://www.m
21
21
## Installation
22
22
Start by creating a new directory and then from within it run `npm init`. This will set us up with a `package.json` for you with the ability to set up some default options.
23
23
24
-
Next, install keystone with `npm install --save keystone`.
24
+
Next, install Keystone with `npm install --save keystone`.
25
25
26
-
At this point, we should have a `node_modules` directory and keystone should have been added to the `package.json`.
26
+
At this point, we should have a `node_modules` directory and Keystone should have been added to the `package.json`.
27
27
28
28
## Initial Setup
29
29
30
-
Create a new file, `keystone.js` and we're ready to start configuring keystone.
30
+
Create a new file, `keystone.js` and we're ready to start configuring Keystone.
31
31
32
-
Your `keystone.js` file is the launch file for keystone, which will connect keystone to your database, start both the database connection, and start your server running. This is where we will be adding configuration options to keystone as well, which allow us to change how keystone is running.
32
+
Your `keystone.js` file is the launch file for Keystone, which will connect Keystone to your database, start the database connection, and start your server running. This is where we will be adding configuration options to Keystone as well, which allow us to change how Keystone is running.
33
33
34
-
The minimum file we need to start keystone running is:
34
+
The minimum file we need to start Keystone running is:
35
35
36
36
```javascript
37
-
var keystone =require('keystone');
37
+
var keystone =require('Keystone');
38
38
39
39
keystone.init({
40
40
'cookie secret':'secure string goes here',
@@ -43,11 +43,11 @@ keystone.init({
43
43
keystone.start();
44
44
```
45
45
46
-
First we require keystone, then we run `keystone.init()`. This function sets up keystone's initial starting values. Here we are only providing it a cookie secret, however as we build up our application we are going to come back and add more options here. If you want to check out the full list of options, you can find them [here](/documentation/configuration).
46
+
First we require Keystone, then we run `keystone.init()`. This function sets up Keystone's initial starting values. Here we are only providing it a cookie secret, however as we build up our application we are going to come back and add more options here. If you want to check out the full list of options, you can find them [here](/documentation/configuration).
47
47
48
-
A `cookie secret` is the only option that is technically required to launch keystone, however we'll be fleshing this out as we complete our setup.
48
+
A `cookie secret` is the only option that is technically required to launch Keystone, however we'll be fleshing this out as we complete our setup.
49
49
50
-
Finally, we call `keystone.start()`, which kicks off our keystone app.
50
+
Finally, we call `keystone.start()`, which kicks off our Keystone app.
51
51
52
52
We can now check this runs. Run `node keystone.js` and you should be greeted with:
53
53
@@ -58,7 +58,11 @@ Keystone is ready on http://0.0.0.0:3000
58
58
------------------------------------------------
59
59
```
60
60
61
-
Unfortunately all that's there is a 404 error page. We're going to solve that in [part 3](/getting-started/setting-up/part-3). In [Part 2](/getting-started/setting-up/part-2) we are going to focus on getting the database connected, and the admin UI up and running. You can do these two in either order.
61
+
You should get a 404 page. That's ok! That will be resolved in [part 3](/getting-started/setting-up/part-3) of this guide. In [Part 2](/getting-started/setting-up/part-2) we are going to focus on getting the database connected, and the admin UI up and running. You can do these two in either order.
62
+
63
+
## Next Steps
64
+
Check out [part 2](/getting-started/setting-up/part-2) of this guide, which walks you through setting up your database, or if you want to read more about any of the parts we set up, you can check out these links:
Copy file name to clipboardExpand all lines: docs/Getting Started/Setting-Up/part-2.md
+12-13Lines changed: 12 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ Firstly, we are going to add a `name`. This is used as the site name, and defaul
35
35
36
36
Next, we want to define what our `'user model'` will be. Let's call it `'User'` to keep it simple.
37
37
38
-
We want to set `auth` to be `true` so accessing the keystone admin UI requires a person to log in.
38
+
We want to set `auth` to be `true` so accessing the Keystone admin UI requires a person to log in.
39
39
40
40
Finally we want to set `'auto update'` to be `true`. This is going to make it very easy to get our seed data in to our project.
41
41
@@ -59,7 +59,7 @@ Finally, we are going to add a new line to the file, which is going to import ou
59
59
keystone.import('models');
60
60
```
61
61
62
-
The `import` method allows us to pull in an entire folder, in this case the entire models folder, and will allow us to add as many models as we want without having to come back and let keystone know we've added something new. New models will be noticed each time keystone starts.
62
+
The `import` method allows us to pull in an entire folder, in this case the entire models folder, and will allow us to add as many models as we want without having to come back and let Keystone know we've added something new. New models will be noticed each time Keystone starts.
63
63
64
64
If you want to know more about `keystone.import()` the documentation is [here](/api/methods/import).
65
65
@@ -110,7 +110,7 @@ This is our most basic field here. Every field needs a `type` property defined,
110
110
password: { type:keystone.Field.Types.Password }
111
111
```
112
112
113
-
Our email field is using a keystone-specific field type. This adds a defined shape to the data, as well as a collection of extra validation. For the password field, it will encrypt it for us. In addition, in the keystone admin UI, it will not display the contents of the password field, and will require a password to be entered twice to change it.
113
+
Our email field is using a keystone-specific field type. This adds a defined shape to the data, as well as a collection of extra validation. For the password field, it will encrypt it for us. In addition, in the Keystone admin UI, it will not display the contents of the password field, and will require a password to be entered twice to change it.
114
114
115
115
This takes care of a lot of our password security for us.
Email is similar to password in that it is using a keystone-specific field type, in this case to ensure that when this field is filled, it has the shape of an email. In addition, we have passed a second option of `unique: true`, which forces the field to be unique within the database. No doubling up on email addresses for accounts.
122
122
123
-
// The following para really needs more work. Needs lightness and timing
124
-
If you want to know about all the field types keystone offers, you can find the information find the full list of options in the [field docs](/api/field) Also, for the options like `unique` which are available to all fields, you can read more [here](/api/field/options), for when you are making your own models.
123
+
If you want to know about all the field types Keystone offers, you can find the full list of options in the [Field API documentation](/api/field) Also, for the options like `unique` which are available to all fields, you can read more about the [Field options API](/api/field/options), for when you are making your own models.
125
124
126
-
There are three more parts we are going to need to get our user model working. The first is to register it to keystone. This will tell keystone to include it in its list of models. To do this, add the following line to the bottom of the file:
125
+
There are three more parts we are going to need to get our user model working. The first is to register it to keystone. This will tell Keystone to include it in its list of models. To do this, add the following line to the bottom of the file:
127
126
128
127
```javascript
129
128
User.register();
@@ -169,7 +168,7 @@ User.register();
169
168
170
169
### Adding an update script
171
170
172
-
There's one more thing to do before we can launch our app. We need to have an initial user in our database. We can do this through an update script, which keystone will run on startup.
171
+
There's one more thing to do before we can launch our app. We need to have an initial user in our database. We can do this through an update script, which Keystone will run on startup.
173
172
174
173
Make a new directory called `updates` and make a file `0.0.1-first-user.js` in it. Next we can just drop in the following code:
175
174
@@ -186,7 +185,7 @@ exports.create = {
186
185
187
186
```
188
187
189
-
This will create a user with these details (though the password will be hashed before saving) when keystone is started up. If you want to know more about update scripts, you can find the information [here](/documentation/configuration).
188
+
This will create a user with these details (though the password will be hashed before saving) when Keystone is started up. If you want to know more about update scripts, you can find the information [here](/documentation/configuration).
190
189
191
190
An important note is that you will likely end up committing your update scripts to your project, so you should not include sensitive information in here. Any passwords added in an update script should be manually changed afterwards.
192
191
@@ -232,13 +231,13 @@ Event.register();
232
231
```
233
232
234
233
## Next Steps
235
-
Check out [part 3](/getting-started/setting-up/part-3) of our setting up keystone guide, which walks you through adding your own pages to your site, or if you want to read more about any of the parts we set up, you can check out these links:
234
+
Check out [Part 3 : Routing](/getting-started/setting-up/part-3) of our setting up Keystone guide, which walks you through adding your own pages to your site, or if you want to read more about any of the parts we set up, you can check out these links:
Copy file name to clipboardExpand all lines: docs/Getting Started/Setting-Up/part-3.md
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Part 3: Routing
2
2
3
-
Keystone is designed to do much of the setup of running an [express](expressjs.com) application out of your hands as well as allowing an easy configuration of the options.
3
+
Keystone is designed to do much of the setup of running an [ExpressJS](https://expressjs.com) application out of your hands as well as allowing an easy configuration of the options.
4
4
5
-
Here we are going to add a router to our keystone application, and set up a basic webpage. This will not rely on what was done in part 2.
5
+
Here we are going to add a router to our Keystone application, and set up a basic webpage. This will not rely on what was done in part 2.
6
6
7
7
After that, we are going to set up an API endpoint to retrieve information about the events model, which will be relying on setup we did in [Part 2](/getting-started/setting-up/part-2).
8
8
9
-
For our routing, we are going to be using [pug](pugjs.org) to render our views, however the principles will remain the same for other view engines.
9
+
For our routing, we are going to be using [pug](https://pugjs.org) to render our views, however the principles will remain the same for other view engines.
10
10
11
11
## Setup
12
12
@@ -39,7 +39,7 @@ If you did [part 2](/getting-started/setting-up/part-2), you will have more than
39
39
40
40
As we mentioned in part one, keystone.init allows us to define our initial options for keystone's startup. For configuring our database connection, we are going to add 2 new properties to our `keystone.init`, and then add a line that will import our routes.
41
41
42
-
Our two properties are `views` and `view engine`. The first allows us to set a folder location relative to `keystone.js` to load our view files from. The second sets an engine for keystone to try and render the files with.
42
+
Our two properties are `views` and `view engine`. The first allows us to set a folder location relative to `keystone.js` to load our view files from. The second sets an engine for Keystone to try and render the files with.
43
43
44
44
We are going to want to set them as:
45
45
@@ -64,7 +64,7 @@ Keystone will look for an installed npm package with the same name as the view e
64
64
$ npm install --save pug
65
65
```
66
66
67
-
Finally, we need to add a line to tell keystone where we plan to write our routes.
67
+
Finally, we need to add a line to tell Keystone where we plan to write our routes.
68
68
69
69
```javascript
70
70
keystone.set('routes', require('./routes'));
@@ -92,7 +92,7 @@ The reason for this structure is that it is best to keep the individual routes i
92
92
93
93
Let's fill out our central file, our `routes/index.js`.
94
94
95
-
This file is going to export a function, takes in the express app keystone has built for us, and adds on our individual routes.
95
+
This file is going to export a function, takes in the express app Keystone has built for us, and adds on our individual routes.
The keystone importer gives us a function that allows us to reduce a folder and its contents to an object with the same nesting.
122
+
The Keystone importer gives us a function that allows us to reduce a folder and its contents to an object with the same nesting.
123
123
124
124
We then call `importRoutes` with the directory we want to import, and attach it to an object at `routes.views`. Finally, we can now provide `routes.views.index` as the second argument for our `app.get` function call.
125
125
@@ -180,18 +180,18 @@ html(lang="en")
180
180
Hope you're enjoying learning about keystone. We're close to some very dynamic cool things
181
181
```
182
182
183
-
Check out [pugjs.org](pugjs.org) if you want to know more about pug.
183
+
Check out [pugjs.org](https://pugjs.org) if you want to know more about pug.
184
184
185
-
Now, if we start our keystone app using `node keystone`, we should be able to visit the homepage and see it rendered!
186
-
187
-
[Part 4](/getting-started/setting-up/part-4)
185
+
Now, if we start our Keystone app using `node keystone`, we should be able to visit the homepage and see it rendered!
188
186
189
187
## Next Steps
188
+
Check out [part 4](/getting-started/setting-up/part-4) of our setting up Keystone guide, which walks you through setting up an API endpoint so we can record data to our database from a form.
Copy file name to clipboardExpand all lines: docs/Getting Started/Setting-Up/part-4.md
+16-7Lines changed: 16 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,11 +60,11 @@ Your source tree should look like the following:
60
60
|--keystone.js
61
61
```
62
62
63
-
## Adding a`addEvent` view
63
+
## Adding an`addEvent` view
64
64
65
-
First we want our pair of new files to make up the route and the view, these should be `routes/views/addEvent` and `templates/views/addEvent.pug`.
65
+
First we want our pair of new files to make up the route and the view. These should be `routes/views/addEvent` and `templates/views/addEvent.pug`.
66
66
67
-
As we are not a pug tutorial, here's a page we prepared earlier:
67
+
As this is not a pug tutorial, here's a page we prepared earlier:
68
68
69
69
```jade
70
70
doctype html
@@ -127,7 +127,7 @@ With all this, we can start keystone, and go to our new route, and fill out the
127
127
128
128
We are going to create a new addition to our app, a handler for a post request, and then a request handler that can save the event information back to our database.
129
129
130
-
As this endpoint is not a view, we are going to have to modify our routes object. We are going to create a new folder to importRoutes from, called `api`. Beofre this though, let us set up our `routes/index` for it.
130
+
As this endpoint is not a view, we are going to have to modify our routes object. We are going to create a new folder to importRoutes from, called `api`. Before this though, let us set up our `routes/index` for it.
131
131
132
132
First, we want to add a second property to our routes object to read in our api folder. Our routes object should end up looking like:
133
133
@@ -186,7 +186,7 @@ First, we can create a new item, passing in values we want to use as our initial
186
186
var newEvent =newEvent(req.body);
187
187
```
188
188
189
-
This will return us an object with the properties of an Event from our schema however it has not yet been saved. You can use `newEvent.save()`, which implements mongoose's save method, however keystone provides an `updateItem` function that runs keystone's validators, to make sure the data in the fields complies with keystone's full schema. Yes, updateItem will create an item if it does not exist.
189
+
This will return us an object with the properties of an Event from our schema however it has not yet been saved. You can use `newEvent.save()`, which implements mongoose's save method, however Keystone provides an `updateItem` function that runs keystone's validators, to make sure the data in the fields complies with keystone's full schema. Yes, updateItem will create an item if it does not exist.
190
190
191
191
We can call this like so:
192
192
@@ -225,6 +225,15 @@ Event.updateItem(newEvent, req.body, function (error) {
225
225
});
226
226
```
227
227
228
-
## Next Steps
228
+
## Congratulations
229
+
Well done! You have finished this four-step guide to getting started with Keystone, and you now have a basic Keystone app, complete with an API for form handling that adds data to our database. For more information on list options and the field types Keystone supports, browse the [database guide](/documentation/database/).
230
+
231
+
You should also [Follow @KeystoneJS on Twitter](https://twitter.com/keystonejs) for news and updates, [Star KeystoneJS on GitHub](https://github.com/keystonejs/keystone), and discuss this guide (or anything KeystoneJS related) on the [KeystoneJS Google Group](https://groups.google.com/d/forum/keystonejs).
0 commit comments