12 Hello World on Node js | MongoDB beginners Tutorials [w/ subs]



00:00:00 – alright so now let's write a simple
00:00:01 – hello world program using know Jeff so
00:00:04 – the first thing we want to do is make a
00:00:07 – new directory call it
00:00:08 – hello world now let's just start writing
00:00:11 – our first note jas application so i'm
00:00:14 – just going to use them to write this but
00:00:16 – you can actually use any text editor
00:00:18 – that you're comfortable with
00:00:19 – so let's open a new file called app that
00:00:23 – Jas and our first application will be
00:00:25 – really simple just love to the console
00:00:28 – hello world so now the way we run this
00:00:32 – is a note to give it the name of our
00:00:35 – application and it prints out hello
00:00:38 – world
00:00:39 – ok so this is looking good it's our
00:00:40 – first application but now let's make an
00:00:43 – actual web server with this so in order
00:00:47 – to make this into a web server let's
00:00:49 – delete this line and now let's say far
00:00:52 – HTTP equals require HTTP HTTP is
00:00:58 – actually built in the note is that the
00:01:00 – library what we're doing up here is
00:01:02 – we're saying we need to use this library
00:01:03 – require HTTP and store a reference to
00:01:07 – this library and the variable HTTP so if
00:01:11 – we go down here now we can save our
00:01:13 – server equals HTTP dot create server and
00:01:19 – passive function for what to do when the
00:01:21 – server receives a request and we get a
00:01:24 – response object as well so when our
00:01:26 – server receives a request request will
00:01:29 – be in the first argument and the object
00:01:32 – for handling the response will be in a
00:01:33 – second argument so we can do is when we
00:01:36 – get any requests we say response not
00:01:39 – right said status 200 content
00:01:43 – ok so first we set this set some
00:01:46 – metadata about corresponds then actually
00:01:49 – done that we actually send the response
00:01:51 – i calling response to that end and send
00:01:55 – hello world
00:01:57 – what this does is it specifies what to
00:01:59 – do when our server receives a request
00:02:00 – but the one part missing here is telling
00:02:04 – our server to listen for incoming
00:02:05 – connections so now let's listen on port
00:02:08 – 8080
00:02:10 – and let's log to the console friendly
00:02:12 – message telling the user that the server
00:02:14 – has successfully started phenomena will
00:02:17 – actually run this by calling node at GS
00:02:19 – you can see our servers running on
00:02:22 – localhost 8080 can do now is we can go
00:02:25 – to our browser and we type localhost
00:02:27 – 8080 get hello world so that is the
00:02:32 – first example of using no chance to
00:02:35 – write a simple server notice we use HTTP
00:02:38 – library but actually know Jeff allows
00:02:41 – you to interact with the client on a
00:02:44 – number of different levels and if you
00:02:46 – wanted to you could actually just open a
00:02:48 – raw TCP connection and interact that way
00:02:52 – for this course will actually be using a
00:02:54 – framework called express so that's one
00:02:56 – level above HTTP and actually handles
00:02:59 – love the routing and details of HTTP for
00:03:03 – us
00:03:04 – alright so those are the basics of
00:03:05 – setting up a simple server running on no
00:03:07 – chance


Video Url:
http://youtu.be/hDTrCFvzYN4

Comments

comments