elstar IT

Fullstack | Java | Tech Speaker | Tech Coach | Frank van der Linden

  • About me
  • Blog license
  • My Open source projects

Quick tip: test HTML pages on a local webserver with NodeJS

14-05-2018 3 responses flinden68 development

At a customer we are building lots of microservices with Spring boot which runs on Pivotal Cloud Foundry hosted at the Azure platform.

Some of these microservices are called from web pages with certain specific information, like field info.

So in our projects we have most of the time a test html page to mimic the actual behavior.

NodeJS http-server to the rescue

there is a very nice NPM package, http-server, to host this test page with a minimal of effort

Easiest way is to install it globally by the following command in a command line.

[dropshadowbox align=”none” effect=”lifted-both” width=”auto” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ]npm install http-server -g[/dropshadowbox]

Now you can use it everywhere.

Next step is to go to the directory in the command line, where the test page is located.

There fire the commando

[dropshadowbox align=”none” effect=”lifted-both” width=”auto” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ]http-server[/dropshadowbox]

In the command line you will see the http server starting and on which port the page is available

nodejs http-server

Tags: development, frontend, nodes

3 thoughts on “Quick tip: test HTML pages on a local webserver with NodeJS”

  1. Eric McCormick says:
    14-05-2018 at 18:43

    Great tip Frank!

    Many people have node/npm installed on their system and it’s easy to have development tooling installed from npm. I generally use the http-server package when *all I need* is a simple server, but I have a couple others installed globally for a similar local dev purpose, but with some added niceties. Here are the two I think are worthy of mention:

    – serve: more of a direct alternative to http-server, it brings some capabilities such as ability to set basic auth via environment variables, has a directory navigation for directories without an index.html. It also copies the localhost with port to your clipboard once you’ve executed it, making it pretty simple. http://npm.im/serve
    – lite-server: a pre-configured version of browser-sync, bringing with it all of browser-sync’s superpowers for monitoring connections and live-reloads on watched file save changes. Advanced configurations of browser-sync options, such as making use of proxies, can be storied into a standardized name space (bs-config.json) for easy storage in your project repo. http://npm.im/lite-browser

    Reply
    1. Frank van der Linden says:
      14-05-2018 at 19:15

      Thanks for the information. Good to know the alternatives

      Reply
  2. Keith Strickland says:
    14-05-2018 at 23:45

    Yup, I’m using http-server in my tooling also. We run it locally with the watch option enabled as we develop. Then when a file is changed we get an automatic refresh of the browser that is connected. Working this way using Domino as a data store, we do need to configure CORS on our development servers. But honestly this isn’t an issue as those are on our local machines also.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • « Quick tip: run your Cloudant data everywhere with CouchDb
  • The slides of my session at Engage 2018 »

Contact me

My name is Frank van der Linden and I am an independent software developer based in the Netherlands. The last 2 years I was awarded as IBM Champion. Also I am on the board of OpenNTF. My specialisations are Java, Web development and Domino.


If you want to hire me, please fill in the Contact form


IBM Champion web badge
Apache Logo

All the code on this blog are under the Apache License 2.0. For more details, see Apache License 2.0

Most recent posts

  • Engage 2020: Hello are you listening, There is stream for everything
  • Spring Cloud Function on Azure run locally
  • Deploy Spring Cloud Function to IBM Cloud
  • Speaking (again) at Engage in a Zoo
  • Congratulations, you’re an IBM Champion (again)!

Latest reactions

  • Spring Cloud Function on Azure run locally - elstar IT on Deploy Spring Cloud Function to IBM Cloud
  • flinden68 on Quick XPages tip: add Fullcalendar plugin to your application
  • Rajesh samal on Quick tip: Swagger support for Spring Webflux
  • dsieyx on Quick XPages tip: add Fullcalendar plugin to your application
  • John on Named as IBM Champion 2019

Archive

  • March 2020
  • February 2020
  • January 2020
  • October 2019
  • September 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • January 2019
  • December 2018
  • October 2018
  • September 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014

Category

  • bluemix
  • business
  • cloudant
  • community
  • development
  • hrassistant
  • openntf
  • running
  • salesforce
  • Springboot
  • Tesla
  • trailrunning
  • Uncategorized
  • watson
  • OpenNTF
  • Collaboration Today
  • XSnippets
  • Stackoverflow
  • IBM Collaboration Solutions
  • Social Business Toolkit
  • About me
  • Dutch curriculum vitae
  • English curriculum vitae
  • Google+
  • LinkedIn profile
  • Twitter
  • Slideshare
  • Blog license
  • My open source projects