How To Run Node Js App On Mac

This page describes the deployment of a Node.js app, assuming that Passenger was installed through the following operating system configuration or installation method: Mac OS X. Is this not how Passenger was installed? Go back to the operating system / installation method selection menu.

In this tutorial we will learn to install TypeScript on Mac using NPM a NodeJS package manager. Step 1: Install Homebrew. Homebrew is a package manager for Mac and helps to easily install and uninstall softwares on a Mac. To install Homebrew run the following command in the terminal.

  1. To run app.js file check 'main': 'app.js' in your package.json file. Then run command $ node app.js That should run your app and check.
  2. There are a few ways to install Node.js. One of the obvious ones is to download the installer from nodejs.org. However, you might not want to be downloading a new installer every time there's a new version out. Here are few alternative ways to update to the latest version of Node.js on a Mac. Nvm is a script-based node version manager.

On this page you will learn how you can deploy your app to a server that is running Passenger. You can either follow these instructions with your own app, or you can use the sample Connect.js app we prepared.

1 Transferring the app code to the server

1.1 Push your code to a Git repository

If you are using our sample app, you can skip to the next step.

We want to transfer our application's code to the server. The easiest way to do that is via Git.

If you have already setup a Git repository, push your application's code to that repository by running this on your local computer:

If you have not already setup a Git repository, go to Github, create a repository and push your application's code there.

1.2 Login to your server, create a user for the app

Login to your server with SSH:

Replace adminuser with the name of an account with administrator privileges or sudo privileges.

Starting from this point, unless stated otherwise, all commands that we instruct you to run should be run on the server, not on your local computer!

Now that you have logged in, you should create an operating system user account for your app. For security reasons, it is a good idea to run each app under its own user account, in order to limit the damage that security vulnerabilities in the app can do. Passenger will automatically run your app under this user account as part of its user account sandboxing feature.

You should give the user account the same name as your app. But for demonstration purposes, this tutorial names the user account myappuser.

We also ensure that that user has your SSH key installed:

1.3 Install Git on the server

Node Js Run

1.4 Pull code

You need to pick a location in which to permanently store your application's code. A good location is /var/www/APP_NAME. Let us create that directory.

Replace myapp and myappuser with your app's name and your app user account's name.

Now let us pull the code from Git:

If you are using our sample app, use this Git clone command instead:

Your app's code now lives on the server at /var/www/myapp/code.

2 Preparing the app's environment

2.1 Login as the app's user

All subsequent instructions must be run under the application's user account. While logged into your server, login under the application's user account as follows: https://girlomg.netlify.app/how-to-uninstall-microsoft-app-on-mac.html.

2.2 Install app dependencies

How

Your application has various dependencies.They must be installed. Most of these dependencies are Javascript libraries, managed by npm. You can install them by running npm install in your app's directory:

Your app may also depend on services, such as PostgreSQL, Redis, etc. Installing services that your app depends on is outside of this tutorial's scope.

3 Configuring Nginx and Passenger

Now that you are done with transferring your app's code to the server and setting up an environment for your app, it is time to configure Nginx so that Passenger knows how to serve your app.

3.1 Go back to the admin account

You have previously logged into your app's user account in order to prepare the app's environment. That user does not have sudo access. In the next steps, you need to edit configuration files, for which sudo access is needed. So you need to switch back to the admin account.

This can be done by simply exiting the shell that was logged into the app's user account. You will then be dropped back to the admin account. For example:

3.2 Edit Nginx configuration file

We need to edit your Nginx configuration file and setup a virtual host entry that points to your app. This virtual host entry tells Nginx (and Passenger) where your app is located.

The location of the Nginx configuration file depends on the Nginx installation prefix you chose while installing Passenger. Assuming you installed Nginx to the default prefix /opt/nginx, you need to open /opt/nginx/conf/nginx.conf:

CCleaner for Mac! Clean up your Mac and keep your browsing behaviour private with CCleaner, the world's favourite computer cleaning tool. The best Mac Cleaner software helps you to do this without iCloud. You do not have to spend additional money if you can locate free space in your Mac itself. Other reasons why you need to consider Mac cleaner software includes the removal of GBs application data that is not often used. Macos cleaner app free download. Download CCleaner for free. Clean your PC of temporary files, tracking cookies and browser junk! Get the latest version here.

Let us add a virtual host entry at the end of that file. At the end of the file, insert:

Replace yourserver.com with your server's host name, replace /var/www/myapp/code with your application's code directory path and replace app.js with your app's entry point file.

When you are done, restart Nginx:

Install Node Js On Mac

(Learn more about restarting Nginx)

3.3 Test drive

You should now be able to access your app through the server's host name! Try running this from your local computer. Replace yourserver.com with your server's hostname, exactly as it appears in the Nginx config file's server_name directive.

If you do not see your app's front page HTML, then these are the most likely causes:

  1. You did not correctly configure your server_name directive. The server_name must exactly match the host name in the URL. For example, if you use the command curl http://45.55.91.235/ to access your app, then the server_name must be 45.55.91.235.
  2. You did not setup DNS records. Setting up DNS is outside the scope of this tutorial. In the mean time, we recommend that you use your server's IP address as the server name.

How To Run Node Js App On Mac Windows 10

Next step

Congratulations, you have successfully deployed your app!

Continue: Deploying updates ยป