- Hands-On Data Structures and Algorithms with JavaScript
- Kashyap Mukkamala
- 149字
- 2021-06-30 19:12:14
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:3000, and that should show you the server status as OK! or give you an error if your server is down.
推薦閱讀
- MySQL數據庫管理實戰
- PHP 從入門到項目實踐(超值版)
- 深度學習經典案例解析:基于MATLAB
- Mastering Python Scripting for System Administrators
- Linux C編程:一站式學習
- Mastering ArcGIS Enterprise Administration
- 移動增值應用開發技術導論
- Zabbix Performance Tuning
- Building Business Websites with Squarespace 7(Second Edition)
- 交互設計師成長手冊:從零開始學交互
- Modular Programming with JavaScript
- Android智能手機APP界面設計實戰教程
- 城市信息模型平臺頂層設計與實踐
- Analytics for the Internet of Things(IoT)
- Flutter for Beginners