HTML and CSS Reference
In-Depth Information
Listing E.1. Node Hello World
Step 2: Run a node application
After you've created your app.js file you should be able to start Node. Issue a command
like the following from your shell or command prompt, making sure you're in your work-
ing directory (you may need to log off and back on for the Node folder to be added to your
node app.js
This command will start Node running in the current directory using the file app.js to de-
termine behavior. Start the Node server with the command shown previously. Once the
Node server is running, point your browser at http://localhost:8080/ and re-create figure
E.1 .
E.1.2. Serving static files with Node
Node is a bare-bones web server, which means many things you might take for granted
with more traditional web servers won't happen in Node, unless you write code to make
them happen. For instance, Node won't transparently transfer any static files that happen
to be sitting in the execution directory. If you want a file called index.html to be sent to the
browser in response to a request, it's up to you to detect the requested URL, locate the file,
and then send it in response.
Search WWH ::

Custom Search