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

Running Express.js in development

To launch our server, we have to add a new script to our package.json.

We will add the following line to the scripts property of the package.json file:

"server": "nodemon --exec babel-node --watch src/server src/server/index.js"

As you can see, we are using a command called nodemon. We need to install it first:

npm install --save nodemon

Nodemon is an excellent tool for running a Node.js application. It can restart your server when the source changes.

For example, to get the above command working follow the steps below:

  1. Furthermore, we must install the @babel/node package, because we are transpiling the back end code with Babel, using the --exec babel-node option. It allows the use of the import statement:
npm install --save-dev @babel/node

Providing --watch as the option following a path or file will permanently track changes on that file or folder and reload the server to represent the latest state of your application. The last parameter refers to the actual file being the starting execution point for the back end.

  1. Start the server now:
npm run server

When you now go to your browser and enter http://localhost:8000, you will see the text Hello World! from our Express.js callback function.

Chapter 3Connecting to the Database, covers how Express.js routing works in detail.

主站蜘蛛池模板: 龙江县| 黑河市| 藁城市| 若尔盖县| 蒙山县| 伊宁县| 团风县| 宾川县| 怀来县| 普格县| 江西省| 阿合奇县| 沧源| 深圳市| 娄烦县| 嵩明县| 那曲县| 讷河市| 光山县| 察哈| 外汇| 房产| 晋中市| 亳州市| 屯门区| 白河县| 吉木乃县| 富宁县| 凭祥市| 庆云县| 马尔康县| 天峻县| 博客| 东明县| 磴口县| 乳源| 阿克| 荔浦县| 宣威市| 屯留县| 克拉玛依市|