Steps to run node http server in visual studio code

青春壹個敷衍的年華 提交于 2019-12-10 12:04:46

问题


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.


回答1:


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/




回答2:


It worked for me from step 1 to 5 on a Windows 7 Pro after solving a proxy problem. Resource: https://jjasonclark.com/how-to-setup-node-behind-web-proxy/



来源:https://stackoverflow.com/questions/52583550/steps-to-run-node-http-server-in-visual-studio-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!