COMP229WEEK2 - Developing Node - Js Web Application11
COMP229WEEK2 - Developing Node - Js Web Application11
console.log('Server running at
http://localhost:3000/');
10/06/2023 Web Application Development 4
Developing Node.js web applications
To start your web server, use your command-line tool and navigate to your working
folder.
Then, run the Node.js CLI tool and run the server.js file as follows:
$ node server
Now, open http://localhost:3000 in your browser and you'll see the Hello
World response.
In this example, the http module is used to create a small web server listening to
the 3000 port.
You begin by requiring the http module and then use the createServer() method
to return a new server object.
As you can see, your application file is using the connect module to create a new
web server.
However, Connect isn't a core module, so you'll have to install it using npm.
As you already know, there are several ways of installing third-party modules.
The easiest one is to install it directly using the npm install command.
Let's revise the previous example to include your first middleware. Change
your server.js file to look like the following code snippet:
app.use(helloWorld);
app.listen(3000);
console.log('Server running at http://localhost:3000/');