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

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.

主站蜘蛛池模板: 广汉市| 聂荣县| 买车| 望城县| 巴林左旗| 木兰县| 郎溪县| 富顺县| 固始县| 南澳县| 惠东县| 通榆县| 科尔| 建瓯市| 紫金县| 大宁县| 红河县| 二连浩特市| 永寿县| 奎屯市| 临澧县| 沐川县| 五家渠市| 巴彦县| 东城区| 兰州市| 博湖县| 富源县| 汉中市| 开鲁县| 和政县| 噶尔县| 太保市| 漾濞| 聊城市| 灵石县| 阿城市| 台南县| 蒙自县| 兰溪市| 二手房|