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

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.

主站蜘蛛池模板: 闸北区| 西青区| 汉阴县| 林周县| 黎平县| 孝感市| 本溪市| 仁寿县| 万安县| 怀来县| 资源县| 孙吴县| 万山特区| 都昌县| 宜兰县| 新兴县| 延川县| 阜康市| 建瓯市| 罗平县| 谢通门县| 句容市| 郸城县| 庆阳市| 萍乡市| 房山区| 石台县| 安乡县| 嘉鱼县| 鹤山市| 宜城市| 宿州市| 青田县| 绥滨县| 清水河县| 鹤岗市| 武邑县| 精河县| 黄梅县| 天长市| 宣威市|