Express: Auto Server Refresh Feature

One problem with the simple Express server is that you have to restart the application every time there is a change to the source code to see the changes implemented. By installing nodemon, you have an “auto-refresh upon source code save” feature. Step 0: Go to Express project root. Step 1: Install nodemon npm install --save-dev nodemon Step 2: Add the following line: "dev": "nodemon index.js" to package.json 1 2 3 4 5 "scripts": { "start": "node index.js", "dev": "nodemon index.js", "test": "echo \"Error..."" }

August 16, 2021 · 1 min · Lei

Steps for creating an Express Server

It is really simple creating an express API server. All you have to do is basically requiring express, creating/importing the JSON data, setting up a route, setting up a listening port, and bam there is API access to your data. Steps for creating an Express API server: Step 1: Importing Express, assigning it to app variable 1 2 const express = require('express') const app = express() Step 2: Creating JSON data ...

August 16, 2021 · 1 min · Lei

Express App.listen

What I’ve found is that if I don’t add the following code to my index.js file, I am not able to run the localhost: 1 2 3 app.listen(PORT, () => { console.log(`Server running on port ${PORT}`) }) The code still runs when you do npm start, but upon end of code, it simply terminates, whereas if you do app.listen, you could inspect the output at a port.

August 16, 2021 · 1 min · Lei

Steps for creating an NPM server

Step 1: npm init in project folder Step 2: Add "start": "node index.js" in package.json, like so: 1 2 3 4 5 6 { "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1" }, }

August 16, 2021 · 1 min · Lei