Starting the Node.js server

Once we have the application shell created, create a file called index.js, which will be the main file of your application; you can call it anything you like, but make sure that you update the main property accordingly in your  package.json.

Now, let's add some code to the index.js file to start an express server:

var express = require('express');
var app = express();

app.listen(3000, function () {
console.log('Chat Application listening on port 3000!')
});

That's it! The server is now up-and-running on the 3000 port. To test it, just add an empty route to tell you whether your application is up or not:

app.get('/', function (req, res) {
res.status(200).send('OK!')
});

You can go to your browser and navigate to localhost:3000and that should show you the server status as OK! or give you an error if your server is down.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.189.99