-
55 |
├── assets ├── alert.png ├── example.png ├── nodejs.png ├── annotated.png ├── index.html.png ├── lhl-logo.png ├── new-file.png ├── no-styles.png ├── hello-world.png ├── open-folder.png ├── server-test.png ├── annotated-alert.png ├── client-folder.png ├── download-chrome.png ├── example-cropped.png ├── hello-browser.png ├── install-express.png ├── terminal-test.png ├── working-alert.png └── download-brackets.png ├── _book ├── images │ └── lhl-logo.png ├── gitbook │ ├── images │ │ ├── favicon.ico │ │ └── apple-touch-icon-precomposed-152.png │ ├── fonts │ │ └── fontawesome │ │ │ ├── FontAwesome.otf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.ttf │ │ │ ├── fontawesome-webfont.woff │ │ │ └── fontawesome-webfont.woff2 │ ├── gitbook-plugin-search │ │ ├── search.css │ │ ├── search-engine.js │ │ ├── search.js │ │ └── lunr.min.js │ ├── gitbook-plugin-lunr │ │ ├── search-lunr.js │ │ └── lunr.min.js │ ├── gitbook-plugin-sharing │ │ └── buttons.js │ ├── gitbook-plugin-highlight │ │ └── ebook.css │ └── gitbook-plugin-fontsettings │ │ ├── fontsettings.js │ │ └── website.css ├── GLOSSARY.html └── content │ ├── part1 │ ├── index.html │ └── dev-tools.html │ ├── final │ └── index.html │ ├── setup │ ├── index.html │ ├── chrome.html │ └── github.html │ └── part2 │ └── index.html ├── content ├── setup │ ├── chrome.md │ ├── nodejs.md │ ├── brackets.md │ ├── README.md │ ├── github.md │ └── cloud9.md ├── final │ └── README.md ├── part1 │ ├── README.md │ ├── dev-tools.md │ ├── final-css.md │ ├── css.md │ └── html.md ├── part2 │ ├── README.md │ ├── node.md │ ├── express.md │ ├── socket.io.md │ └── client-js.md └── part3 │ └── README.md ├── GLOSSARY.md ├── SUMMARY.md └── README.md /assets/alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/alert.png -------------------------------------------------------------------------------- /assets/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/example.png -------------------------------------------------------------------------------- /assets/nodejs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/nodejs.png -------------------------------------------------------------------------------- /assets/annotated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/annotated.png -------------------------------------------------------------------------------- /assets/index.html.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/index.html.png -------------------------------------------------------------------------------- /assets/lhl-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/lhl-logo.png -------------------------------------------------------------------------------- /assets/new-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/new-file.png -------------------------------------------------------------------------------- /assets/no-styles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/no-styles.png -------------------------------------------------------------------------------- /assets/hello-world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/hello-world.png -------------------------------------------------------------------------------- /assets/open-folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/open-folder.png -------------------------------------------------------------------------------- /assets/server-test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/server-test.png -------------------------------------------------------------------------------- /_book/images/lhl-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/_book/images/lhl-logo.png -------------------------------------------------------------------------------- /assets/annotated-alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/annotated-alert.png -------------------------------------------------------------------------------- /assets/client-folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/client-folder.png -------------------------------------------------------------------------------- /assets/download-chrome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/download-chrome.png -------------------------------------------------------------------------------- /assets/example-cropped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/example-cropped.png -------------------------------------------------------------------------------- /assets/hello-browser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/hello-browser.png -------------------------------------------------------------------------------- /assets/install-express.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/install-express.png -------------------------------------------------------------------------------- /assets/terminal-test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/terminal-test.png -------------------------------------------------------------------------------- /assets/working-alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/working-alert.png -------------------------------------------------------------------------------- /assets/download-brackets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/assets/download-brackets.png -------------------------------------------------------------------------------- /_book/gitbook/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/_book/gitbook/images/favicon.ico -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/_book/gitbook/fonts/fontawesome/FontAwesome.otf -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff -------------------------------------------------------------------------------- /_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /_book/gitbook/images/apple-touch-icon-precomposed-152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jugonzal/gitbook-node-chat-tutorial/HEAD/_book/gitbook/images/apple-touch-icon-precomposed-152.png -------------------------------------------------------------------------------- /content/setup/chrome.md: -------------------------------------------------------------------------------- 1 | # Google Chrome 2 | 3 | Different Web browsers provide different tools for doing Web development. The examples in this workshop will be using Google Chrome. You can [download it from Google](https://www.google.com/chrome/browser/desktop/index.html). 4 | 5 |  6 | 7 | -------------------------------------------------------------------------------- /content/setup/nodejs.md: -------------------------------------------------------------------------------- 1 | # Node.js 2 | 3 | Node.js is a program for running JavaScript code on the server-side. Because we'll be coding a Web server today, we might as well write it in JavaScript because that's the language we code the client-side browser code in. 4 | 5 | Get it from [nodejs.org](https://nodejs.org/). 6 | 7 |  -------------------------------------------------------------------------------- /content/setup/brackets.md: -------------------------------------------------------------------------------- 1 | # Brackets 2 | 3 | Brackets is a free code editor from Adobe. Basically code editors are word processors that only work on plain text files, but they can provide other cool features if they know what programming languages you're using. 4 | 5 | Download Brackets from [brackets.io](http://brackets.io/). 6 | 7 |  8 | 9 | -------------------------------------------------------------------------------- /content/final/README.md: -------------------------------------------------------------------------------- 1 | # Final Thoughts 2 | 3 | This demonstration was a bold attempt at showing you how easy it is to get started with Web development, and that seemingly complex apps can be prototyped relatively quickly with modern software technology and approach. 4 | 5 | Thank you for spending your Saturday with us; I hope you enjoyed it and that you have wonderful weekend! 6 | -------------------------------------------------------------------------------- /content/part1/README.md: -------------------------------------------------------------------------------- 1 | # Part I 2 | 3 | ## HTML and CSS 4 | 5 | While this workshop is meant to teach you Javascript we have prepared a short sequence of exercises that will give you basic concepts about building the front-end to your web application. 6 | 7 | * [HTML](html.md) 8 | * [Dev Tools](dev-tools.md) 9 | * [CSS](css.md) 10 | * [CSS \(Example\)](final-css.md) 11 | 12 | After that, it is time to dive into [JavaScript](../part2/README.md) 13 | -------------------------------------------------------------------------------- /content/part2/README.md: -------------------------------------------------------------------------------- 1 | # Part II 2 | 3 | ## JavaScript: jQuery, Node, Express, and Web Sockets 4 | 5 | Having spent sometime preparing the look and feel of our web application, it is time we make it do something. This is where we dive into Javascript to code the behaviour. 6 | 7 | * [Client Side](client-js.md) 8 | * [Node](node.md) 9 | * [Express](express.md) 10 | * [Socket IO](socket.io.md) 11 | 12 | If you still have some time, here are some advanced exercises to keep you going: [Enhancements \(Stretch\)](../part3/README.md) 13 | 14 | -------------------------------------------------------------------------------- /GLOSSARY.md: -------------------------------------------------------------------------------- 1 | # devs 2 | Short form for developers. 3 | 4 | # coders 5 | Alias for devs/developers. 6 | 7 | # dependency 8 | Any software (tool or third party code) that our project needs in order to function. 9 | 10 | # a hack 11 | Using a technology in a way that is was not intended, but nonetheless works. 12 | 13 | # IDE 14 | Integrated Development Environment; everything you need to develop software in one interface, split into multiple sections usually. 15 | 16 | # library 17 | A package of code that performs a specific function and can be used by other code. 18 | 19 | # third party 20 | Someone or some team other than ourselves or our team that wrote some code that we're using on our project. Can be open source or proprietary. 21 | -------------------------------------------------------------------------------- /content/setup/README.md: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | Since we only have a few hours to get you up to speed on being a Javascript Developer, you would benefit from completing these steps before you arrive to the Workshop. 4 | 5 | Don't worry if you run into any issues. Our mentors will be ready to help you get set up upon your arrival. 6 | 7 | * You'll need a modern browser: [Chrome](chrome.md) 8 | * If you don't have a text editor where you can code we recommend [Brackets](brackets.md) 9 | * We'll share some code during the Workshop. Having an account on [GitHub](github.md) will speed things up. 10 | * You will develop Web server using Javascript. Install [Node.js](nodejs.md) 11 | * If you can't install Node, you can still participate but will need [Cloud9](cloud9.md) 12 | 13 | And once you are done, move on to learn about [HTML & CSS](../part1/README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [Introduction](README.md) 4 | * [Setup](content/setup/README.md) 5 | * [Chrome](content/setup/chrome.md) 6 | * [GitHub](content/setup/github.md) 7 | * [Brackets](content/setup/brackets.md) 8 | * [Node.js](content/setup/nodejs.md) 9 | * [Cloud9](content/setup/cloud9.md) 10 | * [Part I - HTML & CSS](content/part1/README.md) 11 | * [HTML](content/part1/html.md) 12 | * [Dev Tools](content/part1/dev-tools.md) 13 | * [CSS](content/part1/css.md) 14 | * [CSS \(Example\)](content/part1/final-css.md) 15 | * [Part II - JavaScript](content/part2/README.md) 16 | * [Client Side](content/part2/client-js.md) 17 | * [Node](content/part2/node.md) 18 | * [Express](content/part2/express.md) 19 | * [Socket IO](content/part2/socket.io.md) 20 | * [Part III - Enhancements \(Stretch\)](content/part3/README.md) 21 | * [Final Thoughts](content/final/README.md) 22 | 23 | -------------------------------------------------------------------------------- /content/setup/github.md: -------------------------------------------------------------------------------- 1 | # GitHub 2 | 3 | [GitHub](https://github.com/) is where a huge amount of open source code resides. Almost every software developer (whether they are Web, mobile, desktop or other) has a GitHub account these days. It also has some great developer workflow features. 4 | 5 | You will need to sign up for a GitHub account. If you already have one, please sign in. 6 | 7 | # Git 8 | 9 | GitHub is centered around an open source Version Control System (VCS) called Git. 10 | 11 | It's like Dropbox for coders. We need to make sure our project codebase is synced to a central server not only for backup purposes but also to share with other devs working on the same project. 12 | 13 | It gives us a lot more control than Dropbox though, and is not nearly as easy to use. That said, it's probably the most popular VCS today and continues to grow at a rapid pace, thanks to services like GitHub especially. 14 | 15 | If you were developing today's app on your own machine, you'd be installing Git. We've saved you that trouble, so no action required here. 16 | -------------------------------------------------------------------------------- /_book/gitbook/gitbook-plugin-search/search.css: -------------------------------------------------------------------------------- 1 | /* 2 | This CSS only styled the search results section, not the search input 3 | It defines the basic interraction to hide content when displaying results, etc 4 | */ 5 | #book-search-results .search-results { 6 | display: none; 7 | } 8 | #book-search-results .search-results ul.search-results-list { 9 | list-style-type: none; 10 | padding-left: 0; 11 | } 12 | #book-search-results .search-results ul.search-results-list li { 13 | margin-bottom: 1.5rem; 14 | padding-bottom: 0.5rem; 15 | /* Highlight results */ 16 | } 17 | #book-search-results .search-results ul.search-results-list li p em { 18 | background-color: rgba(255, 220, 0, 0.4); 19 | font-style: normal; 20 | } 21 | #book-search-results .search-results .no-results { 22 | display: none; 23 | } 24 | #book-search-results.open .search-results { 25 | display: block; 26 | } 27 | #book-search-results.open .search-noresults { 28 | display: none; 29 | } 30 | #book-search-results.no-results .search-results .has-results { 31 | display: none; 32 | } 33 | #book-search-results.no-results .search-results .no-results { 34 | display: block; 35 | } 36 | -------------------------------------------------------------------------------- /content/part1/dev-tools.md: -------------------------------------------------------------------------------- 1 | # Dev Tools 2 | 3 | With your ugly white page open, right click somewhere on the page (anywhere, really) and you'll notice an inspect element option. 4 | 5 |  6 | 7 | Clicking that unlocks a most powerful yet kind-of secret feature that all major browsers have: **Dev Tools** (aka a Web Inspector). 8 | 9 |  10 | 11 | Hover over the HTML source code shown and notice that you can not only use it to inspect the page, but you can also edit it right there (double click the code) to see how it affects the page. 12 | 13 | Our browser gives us a live editor! Why? It's specifically there for developers to inspect _any_ page on the internet, to see how its HTML (and other things) are written. 14 | 15 | By the way, any changes you make through this editor are just experiments and won't actually "stick". If you refresh the page the changes go away. They don't save into your source code directly. 16 | 17 | Play around with it a bit more to get the hang of the "Elements" tab in the Dev Tools. 18 | 19 | Then select (click) the `
` tag and on the right side you'll see something like this. 20 | 21 |  22 | 23 | And what if I double click inside those weird sideways mustaches and type in the following. 24 | 25 |  26 | 27 | That, my friend, was CSS. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | 3 | # Introduction 4 | 5 | Hello and thank you for joining us for this JavaScript Essentials Workshop. 6 | 7 | My name is Juan Gonzalez and I am your Lighthouse Labs instructor today. 8 | 9 | My background is in software development, focusing on Web technologies. I started programming at a young age, selling my first piece of code at age 16 and eventually building very large web systems for large companies. 10 | 11 | For the past 10 years I have also been involved in some very interesting startups. 12 | 13 | ## The goal 14 | 15 | Today's goal is to get acquainted with JavaScript-based Web programming by creating a simple chat application. We'll use modern tools \(Node.js, Web Sockets, etc.\) and touch upon many different technologies. 16 | 17 | The objective is not to fully understand every line of code, but to understand server-client architecture and to be inspired by how much can be created with so little code. 18 | 19 | ## Pair programming 20 | 21 | You're encouraged to buddy up with one other person. That said, both of you should ideally do the setup work individually on your own laptops. 22 | 23 | ## The product 24 | 25 | The finished app that we'll be building in just a few hours today will look and feel much like this. 26 | 27 |  28 | 29 | Let's get started with some [Setup](content/setup/README.md) or if you feel you can go faster here is a [Summary](SUMMARY.md) of all we'll cover. 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /content/part2/node.md: -------------------------------------------------------------------------------- 1 | # Node (JavaScript on the server)! 2 | 3 | So far we've been building a website with some static content and a bit of client-side interactivity. 4 | 5 | It's time to take it up a notch and graduate to "Web application" status. Server-side app logic is what separates a site from an app. 6 | 7 | ## Step 1 8 | 9 | Move all the "client" side files into their own folder called **client**. 10 | 11 |  12 | 13 | ## Step 2 14 | 15 | Now let's add another JavaScript file to be run on the server side which will power the logic for our chat application. Call it **server.js** and put it at the top level (at the same level as the **client** folder.) 16 | 17 | In it, put this one test line of code, to print a message to the screen so we know that it is working. 18 | 19 | ```javascript 20 | console.log('hello from our node script!'); 21 | ``` 22 | 23 |  24 | 25 | ## Step 3 26 | 27 | Let's run it. Open up the **Terminal** app on MacOS or **cmd.exe** on Windows to get to a command prompt. 28 | 29 | Next you'll have to change the working directory to the one where your project files are. In the example below I used the commands: 30 | 31 | ``` 32 | cd Lighthouse\ Labs 33 | ``` 34 | 35 | Then to run the file I did the command: 36 | 37 | ``` 38 | node server.js 39 | ``` 40 | 41 | The output should look like this. 42 | 43 | ``` 44 | hello from our node script! 45 | ``` 46 | 47 | And there's our message, nice! 48 | 49 | -------------------------------------------------------------------------------- /_book/gitbook/gitbook-plugin-search/search-engine.js: -------------------------------------------------------------------------------- 1 | require([ 2 | 'gitbook', 3 | 'jquery' 4 | ], function(gitbook, $) { 5 | // Global search objects 6 | var engine = null; 7 | var initialized = false; 8 | 9 | // Set a new search engine 10 | function setEngine(Engine, config) { 11 | initialized = false; 12 | engine = new Engine(config); 13 | 14 | init(config); 15 | } 16 | 17 | // Initialize search engine with config 18 | function init(config) { 19 | if (!engine) throw new Error('No engine set for research. Set an engine using gitbook.research.setEngine(Engine).'); 20 | 21 | return engine.init(config) 22 | .then(function() { 23 | initialized = true; 24 | gitbook.events.trigger('search.ready'); 25 | }); 26 | } 27 | 28 | // Launch search for query q 29 | function query(q, offset, length) { 30 | if (!initialized) throw new Error('Search has not been initialized'); 31 | return engine.search(q, offset, length); 32 | } 33 | 34 | // Get stats about search 35 | function getEngine() { 36 | return engine? engine.name : null; 37 | } 38 | 39 | function isInitialized() { 40 | return initialized; 41 | } 42 | 43 | // Initialize gitbook.search 44 | gitbook.search = { 45 | setEngine: setEngine, 46 | getEngine: getEngine, 47 | query: query, 48 | isInitialized: isInitialized 49 | }; 50 | }); -------------------------------------------------------------------------------- /content/setup/cloud9.md: -------------------------------------------------------------------------------- 1 | # Cloud9.io 2 | 3 | Cloud9 is amazing. It is for developers what Google docs is for MS Office. BTW if you still use MS Word and Excel instead of Google docs/drive for your spreadsheets and documents, you're living in the 2000s. All the cool kids are living in 2010s. 4 | 5 | Anyway, so what is Cloud9? I'm not surprised you're asking. There are many devs out there that don't know about c9 just yet... Just like how MS Office is still widely used. 6 | 7 | Here's the thing... it takes a lot of time and effort to setup your computer for writing software. A whole bunch of libraries and tools to install, and it's especially hard to make sure every developer on the same team has the exact same versions for all the dependencies. 8 | 9 | This is big hurdle especially when getting started with code. Cloud9 gives us a pre-configured machine in the cloud as well as a really slick IDE right in the browser. As long as you have internet, you can immediately start coding like a _Real Developer_™. 10 | 11 | ## Sign up 12 | 13 | So with that said, go ahead and [sign up for a c9 account on their website](https://c9.io/web/sign-up/free). _Use your github profile_ to sign up: 14 | 15 |  16 | 17 | Once you've done that, create a new workspace titled "chat-app". You can keep it public and select "Custom" as the type. 18 | 19 |  20 | 21 | At this point c9 will open a new browser tab and launch the editor. You're all set to start working on our app! -------------------------------------------------------------------------------- /content/part3/README.md: -------------------------------------------------------------------------------- 1 | # Enhancements as Challenges (Stretch) 2 | 3 | You may have noticed some bugs and broken features with this app. 4 | 5 | ## 1. Initial field - Part I 6 | 7 | The name/initial input field (the first input box) is not being used at all. Modify the `app.js` so that it sends (emits) the text as something like `"KV says: hello"` where `"KV"` is from the first input field (with `id="you"`) and `"hello"` is from the message field. 8 | 9 | ## 2. Initial field - Part II 10 | 11 | The name/initial input field is actually meant to be 2 letter initials only. Make it so only a maximum of two characters can be entered into that field. 12 | 13 | Hint: Google "html input field maximum length" for a convenient HTML attribute that can be added to your HTML file. 14 | 15 | ## 3. List of Messages 16 | 17 | It would be nice to see the message history on the server anytime you join the chat room. Unfortunately, we don't keep/store a message history on the server at all. 18 | 19 | One way to do this is to create an empty [array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) that stores the messages. 20 | 21 | Then, whenever a message is received on the server, it can [push](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) (append) that message string into the array. 22 | 23 | Then whenever a user (new socket) connects to the server, (on `connection`) the server could iterate over all the messages in the array and `emit` them to that new client/socket. 24 | -------------------------------------------------------------------------------- /content/part1/final-css.md: -------------------------------------------------------------------------------- 1 | # Example CSS 2 | 3 | There is no "one right solution" to CSS. There are many approaches to solving the same thing (admittedly in some cases there are some better than others) not to mention all the creative freedom you get with it. 4 | 5 | That said, if you are looking for one possible CSS file so that you can move on, scroll on down! 6 | 7 | ```css 8 | body { 9 | background-color: white; 10 | color: #303030; 11 | font-family: 'Helvetica Neue', Arial, sans-serif; 12 | font-size: 15px; 13 | margin: 20px; 14 | } 15 | 16 | main { 17 | background-color: #f0f0f0; 18 | border-radius: 6px; 19 | box-shadow: 3px 3px 12px #c8c8c8; 20 | margin: 20px auto; 21 | max-width: 450px; 22 | padding: 20px; 23 | } 24 | 25 | ol { 26 | list-style: none; 27 | margin-bottom: 20px; 28 | margin-top: 0; 29 | padding: 0; 30 | } 31 | 32 | li { 33 | padding: 10px; 34 | } 35 | 36 | li:nth-child(odd) { 37 | background-color: #e3e3e3; 38 | border-radius: 6px; 39 | } 40 | 41 | form { 42 | background-color: lightsteelblue; 43 | border-radius: 6px; 44 | margin: 0; 45 | padding: 10px; 46 | } 47 | 48 | button { 49 | background-color: cornflowerblue; 50 | border: none; 51 | border-radius: 3px; 52 | color: white; 53 | font-size: 15px; 54 | font-weight: bold; 55 | padding: 5px 10px; 56 | text-transform: uppercase; 57 | } 58 | 59 | input { 60 | border: none; 61 | border-radius: 3px; 62 | font-size: 15px; 63 | padding: 5px; 64 | } 65 | 66 | #initials { 67 | width: 40px; 68 | } 69 | 70 | #message { 71 | width: 315px; 72 | } 73 | ``` 74 | -------------------------------------------------------------------------------- /_book/gitbook/gitbook-plugin-lunr/search-lunr.js: -------------------------------------------------------------------------------- 1 | require([ 2 | 'gitbook', 3 | 'jquery' 4 | ], function(gitbook, $) { 5 | // Define global search engine 6 | function LunrSearchEngine() { 7 | this.index = null; 8 | this.store = {}; 9 | this.name = 'LunrSearchEngine'; 10 | } 11 | 12 | // Initialize lunr by fetching the search index 13 | LunrSearchEngine.prototype.init = function() { 14 | var that = this; 15 | var d = $.Deferred(); 16 | 17 | $.getJSON(gitbook.state.basePath+'/search_index.json') 18 | .then(function(data) { 19 | // eslint-disable-next-line no-undef 20 | that.index = lunr.Index.load(data.index); 21 | that.store = data.store; 22 | d.resolve(); 23 | }); 24 | 25 | return d.promise(); 26 | }; 27 | 28 | // Search for a term and return results 29 | LunrSearchEngine.prototype.search = function(q, offset, length) { 30 | var that = this; 31 | var results = []; 32 | 33 | if (this.index) { 34 | results = $.map(this.index.search(q), function(result) { 35 | var doc = that.store[result.ref]; 36 | 37 | return { 38 | title: doc.title, 39 | url: doc.url, 40 | body: doc.summary || doc.body 41 | }; 42 | }); 43 | } 44 | 45 | return $.Deferred().resolve({ 46 | query: q, 47 | results: results.slice(0, length), 48 | count: results.length 49 | }).promise(); 50 | }; 51 | 52 | // Set gitbook research 53 | gitbook.events.bind('start', function(e, config) { 54 | var engine = gitbook.search.getEngine(); 55 | if (!engine) { 56 | gitbook.search.setEngine(LunrSearchEngine, config); 57 | } 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /content/part2/express.md: -------------------------------------------------------------------------------- 1 | # Express for our web server 2 | 3 | So far we've created a Node script that prints something out to the terminal, which is great. Instead of doing that though, we need it to do something real. 4 | 5 | In our case, we're building a web server, more specifically a _chat 'server'_. So we need to listen for incoming HTTP requests and then send down the HTML, CSS and JavaScript that we wrote earlier for our chat client. 6 | 7 | While Node comes with basic HTTP handling support, a very (probably the most) popular 3rd party library (called "modules" in the Node community) named **Express** is used by most developers writing Web servers in Node. We shall use it too! 8 | 9 | ## Step 1 10 | 11 | Let's make sure our folder is ready to work with other libraries. We do this by initializing our folder: 12 | 13 | ``` 14 | npm init -y 15 | ``` 16 | 17 | Once this command runs, you will simple notice a new file `package.json` in your folder. Let's install and save the Express library into our project by running this command from the command line that we have open. 18 | 19 | ``` 20 | npm install express 21 | ``` 22 | 23 | This downloads some code using the Node Package Manager (NPM) that we can use to make our lives easier. 24 | 25 |  26 | 27 | Now we can start using it. Type out the following JavaScript code into the **server.js** file. 28 | 29 | ```javascript 30 | var express = require('express'); 31 | var app = express(); 32 | 33 | var http = require('http'); 34 | var server = http.Server(app); 35 | 36 | app.use(express.static('client')); 37 | 38 | server.listen(8080, function() { 39 | console.log('Chat server running'); 40 | }); 41 | ``` 42 | 43 | ### Explanation 44 | 45 | So a bunch of new code and syntax was just introduced there. Let's attempt to break it down. 46 | 47 | The first few lines are just loading external modules. We then tell the Express app to server all static content from the **client** folder. 48 | 49 | When all the setup work is done, we then tell the server to listen in on a certain port (in this case 8080.) 50 | 51 | So for now it's a simple web server serving only static (HTML, CSS and JavaScript) files to any HTTP/Web traffic coming its way. 52 | 53 | Let's try it out by running it using the same command as before. 54 | 55 | ``` 56 | node server.js 57 | ``` 58 | 59 | Now visit` which means "paragraph" and `