zl程序教程

您现在的位置是:首页 >  后端

当前栏目

[NPM] Use npx to run commands with different Node.js versions

JSnpmNode to with use run different
2023-09-14 09:00:49 时间

We will use npx to run a package using different versions of Node.js. This can become valuable when testing the various new features that are introduced in versions of Node.js.

 

For example this code:

let a = { one: 1, two: 2 }; console.log( { ...a, three: 3 } );

 

If we run this code with node@8.2.1, because version 8.2.1 did not yet have support for object spread. It makes sense why we would get an unexpected token error at the ...a location.

 

We can ask NPX to run with a different node version:

npx -p node@8.3.1 -- node index.js