最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to run a website developed with node.js in local? - Stack Overflow

programmeradmin5浏览0评论

I would like to run a website developed with node.js in local. I already installed node.js but when I lauch a .js file on my terminal, nothing happen ( $ node file.js ) Also, I guess I have to simulate a server ? How can I do that with node?

I would like to run a website developed with node.js in local. I already installed node.js but when I lauch a .js file on my terminal, nothing happen ( $ node file.js ) Also, I guess I have to simulate a server ? How can I do that with node?

Share Improve this question edited Apr 24, 2017 at 12:07 Cœur 38.8k25 gold badges205 silver badges277 bronze badges asked Oct 25, 2015 at 16:53 MichaëlMichaël 6192 gold badges8 silver badges30 bronze badges 2
  • We can't really help you unless you show us your code and explain much more specifically what you're trying to acplish. node.js is just a Javascript run-time environment. It doesn't start a web server by default. You can add code to start a web server. It sounds like perhaps you need to find and follow a tutorial on setting up a web site with node.js and Express. – jfriend00 Commented Oct 25, 2015 at 18:18
  • If, this is really just a general question for "how to I make a web site with node.js", then that is far too broad for Stack Overflow. Instead, you should do some Google research on your own (as there are thousands of tutorials out there on this topic) and then post a question when you have specific code running and you got stuck on some particular issue. – jfriend00 Commented Oct 25, 2015 at 18:24
Add a ment  | 

2 Answers 2

Reset to default 1

You can start a simple server with the example that can be found on nodejs:

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");

console.log('Server running at http://127.0.0.1:1337/');

https://nodejs/en/about/

To develop a website it is very helpful to use a web framework such as Express.

http://expressjs./

You should use:

npm start file.js

but also be sure to check out nodemon, which is very helpful for debugging - it restarts your app on code change.

Also be sure to check out the express generator, which will set up a node+express app that you can check out to figure how to get the server and routes going.

发布评论

评论列表(0)

  1. 暂无评论