- Create a directory and an npm module for you service using
npm init
from the command line in the directory. This creates apackage.json
file that will configure how that service runs. Useserver.js
instead ofindex.js
- Add express dependancy to your project. From the comman line type:
npm i -s express
This means "node package manager, install (i) and save it to the package.json file (-s) the express package".
- Create a
server.js
file like:
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
- An end point that does something useful...
app.get('/users/:userId/books/:bookId', function (req, res) {
res.send(req.params)
})
Side stuff:
linux commands cd - change directory ls - list files cd .. go to the parent directory pwd - show the current directory mkdir - make dir