Skip to content

Create the Start Script

Video Lecture

Create the Start Script Create the Start Script

Description

When running on production, we don't need to use nodemon, concurrently or have TSC watching our source code for any changes we make to the files.

TypeScript has already compiled our code into JavaScript compatible for the browser and NodeJS. So we also don't need TypeScript to be installed on production.

So,

We can create a more simplified starting script that will just start the main server.js in NodeJS.

Open the package.json and add the highlighted line below to the scripts node

{
...
  "scripts": {
    "dev": "concurrently -k \"tsc -p ./src/server -w\" \"tsc -p ./src/client -w\" \"nodemon ./dist/server/server.js\"",
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node ./dist/server/server.js"
  },
...

You can now start your project by typing

npm start

Note

Note that we only used npm start and not npm run start. The run option is not necessary. npm start is an alias for npm run start. You can use the longer version if you prefer.

Other aliases you may see used occasionally are,

npm test

npm restart

npm stop

Comments