A Simple Node.js Server
First, import the code that you need.
Then, call the code.
Then, listen for some event happening.
Finally, define a callback that runs when the event happens
• The difference here is that instead of creating a server directly, we've got a
helper function named Express.
• Among other things, calling this function creates a server, so we'll store that
in a variable named server.
• We're still defining a request callback function, but this time, instead of
listening for a request in the server.on method, we're using a different
method named get on that Express server.
• And we're passing a string parameter that contains a single forward slash
and that request callback.
• We're also still listening on port 3000.
• That get method means that our app is going to listen for an HTTP get
request at a certain path.
• A single slash is a way to say the root path, so this callback function will run
whenever the root path is requested.
• Inside of the server callback, instead of response.writehead and
response.end, we're calling response.status and response.send.
• This is the Express way to respond with an HTTP status code and the data
we want to respond with.
npm install
Running npm install, we can see two new
items.
First, a folder named node-modules, and
second, a file named package.json.
Node-modules contains any code that
you requested to install with the npm
command.
Here you can see that a folder with the
express code is in there, along with a ton
of other dependencies that were included
by installing express.
Next, that package.json file documents
any code that's been installed with npm
install.

A Simple Node.pptx that contain node js goir

  • 1.
  • 2.
    First, import thecode that you need. Then, call the code. Then, listen for some event happening. Finally, define a callback that runs when the event happens
  • 5.
    • The differencehere is that instead of creating a server directly, we've got a helper function named Express. • Among other things, calling this function creates a server, so we'll store that in a variable named server. • We're still defining a request callback function, but this time, instead of listening for a request in the server.on method, we're using a different method named get on that Express server. • And we're passing a string parameter that contains a single forward slash and that request callback. • We're also still listening on port 3000. • That get method means that our app is going to listen for an HTTP get request at a certain path. • A single slash is a way to say the root path, so this callback function will run whenever the root path is requested. • Inside of the server callback, instead of response.writehead and response.end, we're calling response.status and response.send. • This is the Express way to respond with an HTTP status code and the data we want to respond with.
  • 6.
    npm install Running npminstall, we can see two new items. First, a folder named node-modules, and second, a file named package.json. Node-modules contains any code that you requested to install with the npm command. Here you can see that a folder with the express code is in there, along with a ton of other dependencies that were included by installing express. Next, that package.json file documents any code that's been installed with npm install.