Institute of Computer Science
  1. Courses
  2. 2022/23 fall
  3. Web Application Development (LTAT.05.004)
ET
Log in

Web Application Development 2022/23 fall

  • Home
  • Lectures
  • Practicals
  • Homework Submission
  • Message Board

Setting up a Node.js project, and installing nodemon and Express

We assume that Node and NPM are correctly installed on your machine. However, it is better to check their versions in the command line to make sure they were successfully installed.

    > node --version
    > npm --version

If everything is ok, you’ll see their versions.

Node.js programs can be created using JavaScript files, contain JavaScript programming statements and expressions, and have a filename extension of ‘.js’.

To execute a Node.js program, you need to run the Node.js executable for the given environment and pass the name of the file (with or without the JS extension) as the first argument. For example, if our program is within a file named server.js, we can run it by calling the name of the file after the node term in the terminal, as follows:

    > node server

Note: To exit the node environment in the terminal, you need to type

    > ctrl + c 

1. Creating and setting up a Node.js project

Create a folder that will contain your project, and give it the name you want.

Navigate into the created folder, and create a js file (e.g., server.js), which you’ll use to write your code.

1.1 Create .gitignore

A .gitignore file specifies intentionally untracked files that Git should ignore. Therefore, we need to create this file to at least untrack the /node_modules directory/file, which can be done as follows:

Create a file called .gitignore in the root directory of your project, open it, and add the following:

# dependencies
/node_modules

1.2 Creating a package.json file

The package.json file is the heart of Node.js system. It is the manifest file of any Node.js project and contains the metadata of the project.

We used package.json before and you should remember that it includes essential information concerning your app/project as well as the modules it depends on. However, we did not create one, which can be done as follows:

Create a package.json file to store all your project dependencies by typing in the terminal:

    > npm init

Then, follow the instructions (default is ok). When the package.json file is created, try to inspect/check its content.

Note: in earlier versions of Node, the use of --save was required to add the dependency to the package.json file. Anyway, always check the package.json file after installing a new package to be sure that it was installed correctly.

2. Install nodemon

nodemon is a tool that helps developing Node.js applications by automatically restarting the node application when the content of a .js file changes.

To install nodemon, write in the terminal

    > npm install -g nodemon

After installing nodemon, use it to run your application

    > nodemon server

3. Install Express

Express is a framework that enables us to professionally manage our routing requests, and it also makes the code much easier to read and modify.

You can install Express by writing to the terminal

    > npm install express

If it was installed successfully, you should see it listed within the dependencies in the package.json file.

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment