react + express
을 배우려고합니다. 다음은 내가 따르고있는 폴더 구조입니다.routes.js에서 예기치 않은 토큰 가져 오기
app
-client
-components
-home.jsx
-nodemodules
-server
-config.js
-package.json
-routes.js
** Package.json :
{
"name": "job-application",
"version": "1.0.0",
"description": "making a website using MERN ",
"main": "nodemon config.js",
"scripts": {
"start": "node config.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/devarashetty/webApplication.git"
},
"author": "sairam",
"license": "ISC",
"bugs": {
"url": "https://github.com/devarashetty/webApplication/issues"
},
"devDependencies": {
"babel-core": "^6.0.14",
"babel-loader": "^6.0.0",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.1"
},
"dependencies": {
"express": "3.x",
"http": "*",
"react": "*",
"react-dom": "*",
"react-router": "*",
"react-router-dom": "*",
"react-router-config": "*",
"nodemon": "*",
"mongodb": "*",
"semantic-ui-react": "*"
},
"homepage": "https://github.com/devarashetty/webApplication#readme"
}
Routes.js
import HomePage from './client/components/home';
나는 뭐야이 이걸 생각을 가져 오기는 기본이었다 뒤에 이유 오류 Unexpected token import
무엇입니까 함수는 자바 스크립트에서 availble
config.js
var http = require("http");
var mongodb = require("mongodb");
var app = require('express')();
var server = require('http').Server(app);
var routes = require("./routes.js");
var Router = require('react-router');
server.listen(8000);
app.use(function(req, res, next) {
console.log("------------", req.url);
var router = Router.create({
location: req.url,
routes: routes
});
router.run(function(Handler, state) {
var html = React.renderToString(< Handler/>)
return res.render('react_page', {
html: html
})
})
});
var MongoClient = mongodb.MongoClient;
var url = 'mongodb://localhost:27017/catering';
MongoClient.connect(url, function(err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
console.log('Connection established to', url);
db.close();
}
});
@BelminBedak 필자는 package.json 파일을 만들고 필요한 종속성을 추가하고'npm install'을했습니다.'babel'은'es6' 코드를'javascript'로 변환 할 것이기 때문에 나는 또한 그것을 추가했습니다.하지만 아직도 일어난다. –
config.js 코드를 게시하십시오. –
@HariLamichhane 게시 할 예정입니다. –