What are the steps for running the Dist Folder on a Local Machine in Angular 6 and above?

Currently working on an application with Angular6+. After running the command ng build --prod, a dist folder was generated. How can I view or serve this folder on Localhost?

Answer №1

To achieve this, you can utilize the http-server package.

Start by globally installing the package

npm install http-server -g

Then navigate to your project directory (in the terminal) and run

http-server dist/

If you are working with Angular 6 or newer versions (Currently using Angular 10), you need to execute

http-server dist/your-project-name

You can now access your application at http://localhost:8080

Answer №2

Update: For Angular 12 and above, use

ng serve --configuration production

Starting from Angular 7, you can simply run ng serve --prod=true. More info can be found in the documentation: https://angular.io/cli/serve

Although the original question is for Angular 6, I landed here through a Google search, so leaving this note for future reference.

Answer №3

For my situation, I took the following steps:

Firstly, I globally installed http-server

npm install http-server -g

Next, within the project directory (using the terminal), I executed

http-server dist/[your-project-name]

You can now navigate to http://localhost:8080/index.html to see your application. However, every time I refresh the browser page, I need to re-enter /index.html in the URL.


This method was successful with Angular 7.x.x version.

Answer №4

Terminal Instructions:
$ npm install http-server -g

To run your Angular project named "ngx" from the project directory:
$ ng build
$ http-server dist/ngx
Starting up the http-server to serve the files in dist/ngx
Access it at:


Press CTRL-C to stop the server

Enjoy!

Answer №5

Operating System Platforms

 - Setup process for Windows: 
   Install WAMP server from https://wampserver.en.softonic.com/ and launch it.
   Move your dist folder files to c:/wamp/www/(your project name)/
   Create a .htaccess file to redirect your index.html. (Refer to http://www.htaccesstools.com/htaccess-faq/)
   Access your project at http://localhost/(your project name)
   
 - Setup process for Ubuntu:
   Install LAMP server using the guide at https://www.linode.com/docs/web-servers/lamp/install-lamp-stack-on-ubuntu-16-04/
   Start the server on Ubuntu.
   Copy your dist folder files to /opt/lampp/htdocs/(your project name)/
   Create an .htaccess file to redirect your index.html.
   View your project by navigating to http://localhost/(your project name)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am currently facing a problem with the PrimeNG calendar feature that is causing issues with setting the minimum date for December and disabling the minimum year

click here to view image The PrimeNG calendar component is presenting a challenge with the minimum date setting for December 2nd to 31st. It seems to be malfunctioning, causing the minimum year to become disabled. Additionally, when the maxdate is set to ...

What is the reason for the presence of additional mandatory dependencies in the package-lock.json file?

The recent release of React includes breaking changes to the TypeScript typings, causing packages that require "@types/react" with a wildcard version to automatically target this new version and break my project. Initially, I wanted to reach out to projec ...

Dealing with server-side errors while utilizing react-query and formik

This login page utilizes formik and I am encountering some issues: const handleLogin = () => { const login = useLoginMutation(); return ( <div> <Formik initialValues={{ email: "", password: "" }} ...

How to store an imported JSON file in a variable using TypeScript

I am facing a challenge with a JSON file that stores crucial data in the following format { "login": { "email": "Email", "firstName": "First name", "lastName": "Last name", ...

Utilizing custom i18n blocks for Vue 3 and Vuetify 3 to enhance locale messages

Looking to localize messages separately for each component? Check out this example for Vue 2. But how can it be done for Vue 3 and Vuetify 3? Here's what I've tried: package.json "dependencies": { "@mdi/font": "6.5 ...

Tips for making use of incomplete types

Is there a way to reference a type in TypeScript without including all of its required fields, without creating a new interface or making all fields optional? Consider the following scenario: interface Test { one: string; two: string; } _.findWhe ...

Exploring the Usage of Jasmine Testing for Subscribing to Observable Service in Angular's OnInit

Currently, I am facing challenges testing a component that contains a subscription within the ngOnInit method. While everything runs smoothly in the actual application environment, testing fails because the subscription object is not accessible. I have att ...

The imported js elements from Bootstrap are failing to function properly despite being successfully included

I want to utilize the collapse feature from Bootstrap in my project. To do so, I have installed jQuery and popper.js: "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "node_modules/hover.css/css/hover.css", "node_modules/hambur ...

When I refresh my Angular web application, I encounter a '404 error'

Having a two-page web service setup consisting of a Main page and a details page, I encountered an issue. When I double click on the main page data, it successfully directs me to the details page with all the relevant information displayed. However, whenev ...

Running a single test in Angular without using fdescribe or fit

My project has numerous tests that are not being maintained, causing errors when running ng test due to import issues in .spec.ts files. Is there a way to execute a single file test for a service without having to clean up all the tests? Perhaps using Php ...

Tips for maintaining an active Angular PWA while your device is in doze mode

We are currently in the process of creating an angular progressive web application that receives updates from a LightStreamer Server and displays notifications to the user. Since PWAs serve as alternatives to native apps, we are aiming for our app to rem ...

Issue with Framer-motion animation not triggering on exit

Here is a link to the code sandbox In this gif demonstration, it's evident that the notifications are not triggering the exit animation when removed from the DOM (usually after 6 seconds). Why is this happening? I've followed all the suggestion ...

What are the requirements for loading styleUrls in an Angular component?

How can I implement multiple CSS files in the styleUrls array? @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: [conditional statement for loading specific CSS] }) I have attempted it before, bu ...

Encountering the error "Unable to use the '+' operator with 'symbol' type when attempting to combine $route.name"

Looking to retrieve the current route name from a template in order to pass it to a router link (specifically passing the current route to the login view so I can redirect users there after authentication). Everything functions as expected, but when perfo ...

Is it possible to conceal dom elements within an ng-template?

Utilizing ng-bootstrap, I am creating a Popover with HTML and bindings. However, the ng-template keeps getting recreated every time I click the button, causing a delay in the initialization of my component. Is there a way to hide the ng-template instead? ...

Exploring the depths of Angular 6: Unleashing the power of nested

Good evening, I recently created a reactive form that includes a nested array structure for cocktails and ingredients. However, I am facing an issue accessing the ingredient formArray within the cocktail array in my existingFlavForms form. this.existingF ...

Implement a nested filter in Angular 8 to enhance data manipulation

Is it possible to apply a filter inside another filter in this scenario? I have a table of orders with nested tables of services, and I want to only display the orders where the type of service is 'type1'. I tried using the following line of code ...

Tips for injecting a service into a class (not a component)

Can you inject a service into a class that is not a component? Consider the following scenario: Myservice import {Injectable} from '@angular/core'; @Injectable() export class myService { dosomething() { // implementation } } MyClass im ...

The parameter type 'never[]' cannot be assigned to the type 'T | (() => T)' in the argument

Is it possible for the useFetch hook to allow any type of array to be used as the data type? hooks/useFetch.ts: const useFetch = <T extends any[]>(dataUrl: string) => { const [data, setData] = useState<T>([]); const [error, setError] = ...

Are optional parameters in TypeScript distinct from parameters that have the ability to be undefined?

Is there a distinction between the following two code snippets? function sayHello(name?: string) { if (name) { return 'Hello ' + name; } return 'Hello!'; } and function sayHello(name: string | undefined) { if (name) { return &apo ...