How to build a new app from scratch inside a docker container?

Docker is said to help isolate application environment, and help developers run the same environment. BUT all guides, tutorials, courses, etc start from an already built application. So how would i start a new application from scratch, let say in NodeJS?

So recently I’ve started to learn docker, and yes it is useful for packaging an already built application, if i already have everything installed in my local host machine and so on.

BUT how would I start developing a new application? For example in
NodeJS, with no host installation of NodeJS, therefore I can’t npm init my folder. How would I install new packages, how would the node_modules be persistent, and all that?

Here goes some very basis setup I used for packaging and app….THIS IS NOT WORKING FOR ME TO START FROM SCRATCH.

FROM node:10-alpine

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .

CMD [ "npm", "start" ]
version: '3'

    build: .
      - .:/usr/src/app
      - /usr/src/app/node_modules
      - 3000:3000
      - 9229:9229
    command: npm start
  docker-compose up

As seen in the code, i have a custom image, a docker-compose, and a makefile. I can change any piece of it or all of it. What I want is to develop my app with nothing installed in my host machine apart from docker, containers should isolate everything needed for the application, best practice to persist any new package installed during development.

Source: StackOverflow