Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Steps to run node http server in visual studio code

Tags:

node.js

I've been trying and searching everywhere .got nothing but errors and vague steps in tutorials to get this to work.

If you know the steps in visual studio code to run node http server for windows(not debugging node files) guide me or tell me if I'm missing something.

like image 647
Diesel Avatar asked Jan 18 '26 03:01

Diesel


1 Answers

1. Install Node.js

If not already installed, get it here: https://docs.npmjs.com/getting-started/installing-node

It comes with npm (the package manager for acquiring and managing your development libraries)

2. Create a new folder for your project

Somewhere in your drive, create a new folder for your web app.

3. Add a package.json file to the project folder

Then copy/paste the following text:

{ 
   "name": "Demo", 
   "version": "1.0.0", 
   "description": "demo project.", 
   "scripts": { 
     "lite": "lite-server --port 10001", 
     "start": "npm run lite" 
   }, 
   "author": "", 
   "license": "ISC", 
   "devDependencies": { 
     "lite-server": "^1.3.1" 
   } 
}

4. Install the web server

In a terminal window (command prompt in Windows) opened on your project folder, run this command:

npm install

This will install lite-server (defined in package.json), a static server that loads index.html in your default browser and auto refreshes it when application files change.

5. Start the local web server!

(Assuming you have an index.html file in your project folder).

In the same terminal window (command prompt in Windows) run this command:

npm start

Wait a second and index.html is loaded and displayed in your default browser served by your local web server!

lite-server is watching your files and refreshes the page as soon as you make changes to any html, js or css files.

And if you have VS Code configured to auto save (menu File / Auto Save), you see changes in the browser as you type!

Notes:

Do not close the command line prompt until you’re done coding in your app for the day It opens on http://localhost:10001 but you can change the port by editing the package.json file.

Resource: https://blogs.msdn.microsoft.com/cdndevs/2016/01/24/visual-studio-code-and-local-web-server/

like image 172
Fatih Aktaş Avatar answered Jan 20 '26 16:01

Fatih Aktaş



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!