【发布时间】:2022-01-03 22:34:05
【问题描述】:
我正在尝试将一个 js 数组从我的节点 js 后端发送到我的 html,但 HTML 中的对象是一个 Promise 对象,我怎样才能正确发送该数组?
我收到此错误 =
Uncaught SyntaxError: Unexpected identifier
console.log([object Promise]);
后端:
const path = require('path');
const fs = require("fs");
const host = "127.0.0.1";
const port = 1337;
const express = require("express");
const ejs = require("ejs");
const server = express();
server.use(express.static(path.join(__dirname, 'public')));
server.use(express.static(path.join(__dirname + '/js')));//middleware
server.use(express(__dirname));
server.set('view engine','html');
server.engine('html', require('ejs').renderFile);
server.get("*", function(request, response){
response.render('index.html', {obj: productArr});
});
const Shopify = require('shopify-api-node');
const shopify = new Shopify({
shopName: 'this.myshopify.com',
apiKey: 'apikey',
password: 'pass'
});
async function getJson() {
return shopify.product.list();
}
let productArr = getJson();
//console.log(productArr);
server.listen(port, host);
console.log('Running at Port 1337');
前端
<script>
console.log(<%= obj %>);
</script>
【问题讨论】:
标签: javascript html node.js arrays