I am going to use a local installation of Node.js.

We start our Node.js project by going into a new folder (call it tripcost) and typing the command npm init.

Answer the questions (you can also just press enter to get the default values, or use npm init --yes to skip them), and you are ready to go.

We’ll use MongoDB as our database.

If you are unfamiliar with MongoDB, check out my tutorials and install MongoDB on your system:

Done? Great! Install the Node.js package right now with

npm install mongodb

While you’re here, also install Express:

npm install express

Create a server.js file now, where we’ll store our API code, and start requiring Express and MongoDB:

const express = require('express')
const mongo = require('mongodb').MongoClient

Initialize the Express app:

const app = express()

And now we can add the stubs for the API endpoints we support:

app.post('/trip', (req, res) => { /* */ })
app.get('/trips', (req, res) => { /* */ })
app.post('/expense', (req, res) => { /* */ })
app.get('/expenses', (req, res) => { /* */ })

Finally, use the listen() method on app to start the server:

app.listen(3000, () => console.log('Server ready'))

You can run the application using node server.js in the project folder.

Project up to now: https://glitch.com/edit/#!/node-course-project-tripcost-a?path=server.js


Go to the next lesson