From the terminal:
mkdir mern-demo
The following will open up a new window with the new folder loaded as a new project.
From the terminal:
code ./mern-demo
From the terminal inside the new VSC window:
npm init -y
From the terminal:
git init
From the terminal:
touch .gitignore
Add the following content to the new .gitignore file:
node_modules
notes
From the terminal:
touch README.md
npm i -D typescript ts-node nodemon @types/node
./node_modules/.bin/tsc --init
This generates a tsconfig.json file.
Open the tsconfig.json file and uncomment/edit the following:
// ...
"rootDir": "./src", // this tells typescript where to build the source from
// ...
"outDir": "./dist", // this tells typescript where to output the built javascript
From the terminal:
mkdir src
From the terminal:
touch src/dev.ts
Add the following content to /src/dev.ts:
console.log("ts working");
In the scripts block in package.json, add the following content:
"scripts": {
"build": "tsc",
"dev": "nodemon ./src/dev.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
From the terminal:
npm run dev
The application should start using nodemon
, you will see the output from dev.ts a few lines down.
Try saving the dev.ts file with CTRL + S and you will see the file restarts on change.
To stop the script from running, CTRL + C. Sometimes quitting the script will not work, in this case start a new terminal and delete the terminal running the script.
From the terminal:
npm run build
The built JavaScript should appear in the /dist
directory.
Inside the .gitignore file add the following:
node_modules
notes
dist
This will ignore the built JS when pushing to Github.
Make a directory to hold notes, ignored from pushing to Github.
mkdir notes
npm i express
npm i -D @types/express