官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 定边县| 凤庆县| 台北县| 万州区| 宁陕县| 南丹县| 汽车| 房产| 高邑县| 温州市| 长乐市| 义马市| 莱阳市| 潮州市| 安义县| 合山市| 如东县| 乌什县| 鲁山县| 双江| 赤城县| 新龙县| 南丰县| 元江| 吴川市| 潞城市| 常宁市| 芦溪县| 湘潭县| 佛坪县| 屏南县| 仁化县| 木里| 林甸县| 滁州市| 福建省| 华池县| 岢岚县| 鄱阳县| 古蔺县| 平利县|