nodejs 安装 使用
2015-10-26 17:06
411 查看
1.
安装: (https://nodejs.org/en/download/package-manager/)
2.查看安装是否成功
3.
The -g flag means that you are installing express globally on your system.
Now we can create an express application.
The -c states that we want to use stylus for css. You should see the following output:
As per the instructions you'll need to install dependencies so do this
Boot the app
That's all the setup you need. Phew. Now you can boot the app:
With a recent express version this command has changed, so if the app doesn't start you can try
You should see Express server listening on port 3000 and if you open http://127.0.0.1:3000 you'll see the default Express page.
其他参看:http://shapeshed.com/creating-a-basic-site-with-node-and-express/
编写文件 example.js文件
在命令行中执行它:
你就可以通过浏览器访问http://208.43.114.234:1337得到Hello World的响应。
var express = require('express');
var app = express();
// routes will go here
app.get('/api/users', function(req, res) {
var user_id = req.param('id');
var token = req.param('token');
var geo = req.param('geo');
res.send(user_id + ' ' + token + ' ' + geo);
});
// start the server
app.listen(1337, "208.43.14.234");
console.log('Server started! At ' target='_blank'>http://localhost:');
访问: http://208.43.14.234:1337/api/users?id=4&token=sdfa3&geo=us http://shapeshed.com/creating-a-basic-site-with-node-and-express/
安装: (https://nodejs.org/en/download/package-manager/)
curl --silent --location https://rpm.nodesource.com/setup | bash - yum install gcc-c++ make yum -y install nodejs
2.查看安装是否成功
node -v v0.8.21 npm -v 1.2.12
3.
Create an Express site 地址:http://shapeshed.com/creating-a-basic-site-with-node-and-express/
First let's install expressnpm install -g express-generator
The -g flag means that you are installing express globally on your system.
Now we can create an express application.
express -c stylus express_example
The -c states that we want to use stylus for css. You should see the following output:
create : express_example create : express_example/package.json create : express_example/app.js create : express_example/public create : express_example/public/javascripts create : express_example/public/images create : express_example/public/stylesheets create : express_example/public/stylesheets/style.styl create : express_example/routes create : express_example/routes/index.js create : express_example/routes/user.js create : express_example/views create : express_example/views/layout.jade create : express_example/views/index.jade install dependencies: $ cd express_example && npm install run the app: $ node app
As per the instructions you'll need to install dependencies so do this
cd express_example && npm install
Boot the app
That's all the setup you need. Phew. Now you can boot the app:
node app.js
With a recent express version this command has changed, so if the app doesn't start you can try
npm start
You should see Express server listening on port 3000 and if you open http://127.0.0.1:3000 you'll see the default Express page.
其他参看:http://shapeshed.com/creating-a-basic-site-with-node-and-express/
编写文件 example.js文件
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, "208.43.114.234"); console.log('Server running at 208.43.114.234/');
在命令行中执行它:
node example.js
你就可以通过浏览器访问http://208.43.114.234:1337得到Hello World的响应。
var express = require('express');
var app = express();
// routes will go here
app.get('/api/users', function(req, res) {
var user_id = req.param('id');
var token = req.param('token');
var geo = req.param('geo');
res.send(user_id + ' ' + token + ' ' + geo);
});
// start the server
app.listen(1337, "208.43.14.234");
console.log('Server started! At ' target='_blank'>http://localhost:');
访问: http://208.43.14.234:1337/api/users?id=4&token=sdfa3&geo=us http://shapeshed.com/creating-a-basic-site-with-node-and-express/
相关文章推荐
- Creating a basic site with Node.js and Express
- 建立一个node.js服务器(使用express搭建第一个Web环境)
- nodejs小问题:express不是内部或外部命令
- 使用express搭建第一个Web应用【Node.js初学】
- 从零开始nodejs系列文章
- NodeJs
- ubuntu 下node 环境的安装
- Node.js脚本杀掉占用端口的进程
- nodejs安装express时丢人了
- DOM - nodeType 的取值
- [树莓派]安装node环境
- Nodejs学习路线图
- 7个Node.js的Web框架
- 基于node.js的web程序入门
- node.js
- NodeJS环境搭建
- namenode总是启动不了
- 第118讲:Hadoop内存需求量及Namenode内存使用详解学习笔记
- Node.js 命令行程序开发资料
- 3.nodejs权威指南--文件