Copyright © 2022-2025 aizws.net · 网站版本: v1.2.6·内部版本: v1.25.2·
页面加载耗时 0.00 毫秒·物理内存 157.5MB ·虚拟内存 1438.3MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
转到C文件夹。在已经创建的文件夹" projects"中创建一个名为" couchemployees"的文件夹。
打开命令提示符,然后转到该位置。

Start npm init

将文件创建为" app.js",现在的入口点将是app.json:
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const NodeCouchdb = require('node-couchdb');
const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use (bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.get('/', function(req,res){
res.send('Working........');
});
app.listen(3000, function(){
console.log('Server is started om Port 3000');
});

现在使用以下命令:
npm install express body-parser ejs node-couchdb --save

执行以下代码以启动本地服务器:
node app

现在服务器已启动,打开本地浏览器: localhost: 3000。

使用以下代码编辑app.js文件:
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const NodeCouchdb = require('node-couchdb');
const couch = NodeCouchdb({
auth:{
user: 'ajeet'
password: '12345'
}
});
couch.listDatabases().then(function(dbs){
console.log(dbs);
});
const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use (bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.get('/', function(req,res){
res.send('Working........');
});
app.listen(3000, function(){
console.log('Server is started on Port 3000');
});

创建一个文件夹" view",然后在其中创建文件" index.ejs",具有以下代码:
Hello World!
现在对" app.js"文件进行更改:
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const NodeCouchdb = require('node-couchdb');
const couch = NodeCouchdb({
auth:{
user: 'ajeet'
password: '12345'
}
});
couch.listDatabases().then(function(dbs){
console.log(dbs);
});
const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use (bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.get('/', function(req,res){
res.render('index');
});
app.listen(3000, function(){
console.log('Server is started on Port 3000');
})
