A Guide to Setting Up an Express Server
From terminal, run:
> npm init -y
***If terminal is not visible, use shortcut ctrl+`
From terminal, run:
> npm i express
***If terminal is not visible, use shortcut ctrl+`
After installing Express, it will appear as a dependency in package.json file
From terminal, run:
> npm i -D nodemon
***If terminal is not visible, use shortcut ctrl+`
After installing nodemon, it will appear as a dev dependency in package.json file
Add name/value pair within "scripts"
{ . . . "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "nodemon server" }, . . . }
const express = require('express') const PORT = 8080 const app = express() app.listen(PORT, () => console.log(`Server listening on port ${PORT}`))
From terminal, run:
> npm run dev
***If terminal is not visible, use shortcut ctrl+`
Terminal will output the following:
> dev > nodemon server.js [nodemon] 2.0.22 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] starting `node server.js` Server listening on port 8080